Skip to content

Commit efe2c37

Browse files
committed
Merge pull request #3809 from areski/fix-timefield
Fixed TimeField not handling empty values
2 parents edd9c7d + 4e01796 commit efe2c37

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

rest_framework/fields.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,8 @@ def to_representation(self, value):
12041204
)
12051205

12061206
if output_format.lower() == ISO_8601:
1207+
if isinstance(value, six.string_types):
1208+
value = datetime.datetime.strptime(value, '%H:%M:%S').time()
12071209
return value.isoformat()
12081210
return value.strftime(output_format)
12091211

tests/test_fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ class TestTimeField(FieldValues):
10321032
}
10331033
outputs = {
10341034
datetime.time(13, 00): '13:00:00',
1035+
'00:00:00': '00:00:00',
10351036
None: None,
10361037
'': None,
10371038
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy