Skip to content

Commit c6372e3

Browse files
committed
Test for TimeField not handling empty values
1 parent 2abc281 commit c6372e3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

rest_framework/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ def to_representation(self, value):
11391139
)
11401140

11411141
if output_format.lower() == ISO_8601:
1142-
if (isinstance(value, str)):
1142+
if (isinstance(value, six.string_types)):
11431143
value = datetime.datetime.strptime(value, '%Y-%m-%d').date()
11441144
return value.isoformat()
11451145

@@ -1204,7 +1204,7 @@ def to_representation(self, value):
12041204
)
12051205

12061206
if output_format.lower() == ISO_8601:
1207-
if (isinstance(value, str)):
1207+
if (isinstance(value, six.string_types)):
12081208
value = datetime.datetime.strptime(value, '%H:%M:%S').time()
12091209
return value.isoformat()
12101210
return value.strftime(output_format)

tests/test_fields.py

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

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