Skip to content

Commit

Permalink
Simplfy TimeField passing through strings (#4197)
Browse files Browse the repository at this point in the history
* Simplfy TimeField passing through strings
  • Loading branch information
tomchristie authored Jun 14, 2016
1 parent 9406e45 commit 798a971
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ def to_representation(self, value):

output_format = getattr(self, 'format', api_settings.TIME_FORMAT)

if output_format is None:
if output_format is None or isinstance(value, six.string_types):
return value

# Applying a `TimeField` to a datetime value is almost always
Expand All @@ -1209,8 +1209,6 @@ def to_representation(self, value):
)

if output_format.lower() == ISO_8601:
if isinstance(value, six.string_types):
value = datetime.datetime.strptime(value, '%H:%M:%S').time()
return value.isoformat()
return value.strftime(output_format)

Expand Down

0 comments on commit 798a971

Please sign in to comment.