@@ -416,6 +416,7 @@ def __init__(self, classes=None):
416
416
'unix-time' : Serializer .serialize_unix ,
417
417
'duration' : Serializer .serialize_duration ,
418
418
'date' : Serializer .serialize_date ,
419
+ 'time' : Serializer .serialize_time ,
419
420
'decimal' : Serializer .serialize_decimal ,
420
421
'long' : Serializer .serialize_long ,
421
422
'bytearray' : Serializer .serialize_bytearray ,
@@ -999,6 +1000,20 @@ def serialize_date(attr, **kwargs):
999
1000
t = "{:04}-{:02}-{:02}" .format (attr .year , attr .month , attr .day )
1000
1001
return t
1001
1002
1003
+ @staticmethod
1004
+ def serialize_time (attr , ** kwargs ):
1005
+ """Serialize Time object into ISO-8601 formatted string.
1006
+
1007
+ :param datetime.time attr: Object to be serialized.
1008
+ :rtype: str
1009
+ """
1010
+ if isinstance (attr , str ):
1011
+ attr = isodate .parse_time (attr )
1012
+ t = "{:02}:{:02}:{:02}" .format (attr .hour , attr .minute , attr .second )
1013
+ if attr .microsecond :
1014
+ t += ".{:02}" .format (attr .microsecond )
1015
+ return t
1016
+
1002
1017
@staticmethod
1003
1018
def serialize_duration (attr , ** kwargs ):
1004
1019
"""Serialize TimeDelta object into ISO-8601 formatted string.
@@ -1230,6 +1245,7 @@ def __init__(self, classes=None):
1230
1245
'unix-time' : Deserializer .deserialize_unix ,
1231
1246
'duration' : Deserializer .deserialize_duration ,
1232
1247
'date' : Deserializer .deserialize_date ,
1248
+ 'time' : Deserializer .deserialize_time ,
1233
1249
'decimal' : Deserializer .deserialize_decimal ,
1234
1250
'long' : Deserializer .deserialize_long ,
1235
1251
'bytearray' : Deserializer .deserialize_bytearray ,
@@ -1763,6 +1779,20 @@ def deserialize_date(attr):
1763
1779
# This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
1764
1780
return isodate .parse_date (attr , defaultmonth = None , defaultday = None )
1765
1781
1782
+ @staticmethod
1783
+ def deserialize_time (attr ):
1784
+ """Deserialize ISO-8601 formatted string into time object.
1785
+
1786
+ :param str attr: response string to be deserialized.
1787
+ :rtype: datetime.time
1788
+ :raises: DeserializationError if string format invalid.
1789
+ """
1790
+ if isinstance (attr , ET .Element ):
1791
+ attr = attr .text
1792
+ if re .search (r"[^\W\d_]" , attr , re .I + re .U ):
1793
+ raise DeserializationError ("Date must have only digits and -. Received: %s" % attr )
1794
+ return isodate .parse_time (attr )
1795
+
1766
1796
@staticmethod
1767
1797
def deserialize_rfc (attr ):
1768
1798
"""Deserialize RFC-1123 formatted string into Datetime object.
0 commit comments