@@ -416,6 +416,7 @@ def __init__(self, classes=None):
416416 'unix-time' : Serializer .serialize_unix ,
417417 'duration' : Serializer .serialize_duration ,
418418 'date' : Serializer .serialize_date ,
419+ 'time' : Serializer .serialize_time ,
419420 'decimal' : Serializer .serialize_decimal ,
420421 'long' : Serializer .serialize_long ,
421422 'bytearray' : Serializer .serialize_bytearray ,
@@ -999,6 +1000,20 @@ def serialize_date(attr, **kwargs):
9991000 t = "{:04}-{:02}-{:02}" .format (attr .year , attr .month , attr .day )
10001001 return t
10011002
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+
10021017 @staticmethod
10031018 def serialize_duration (attr , ** kwargs ):
10041019 """Serialize TimeDelta object into ISO-8601 formatted string.
@@ -1230,6 +1245,7 @@ def __init__(self, classes=None):
12301245 'unix-time' : Deserializer .deserialize_unix ,
12311246 'duration' : Deserializer .deserialize_duration ,
12321247 'date' : Deserializer .deserialize_date ,
1248+ 'time' : Deserializer .deserialize_time ,
12331249 'decimal' : Deserializer .deserialize_decimal ,
12341250 'long' : Deserializer .deserialize_long ,
12351251 'bytearray' : Deserializer .deserialize_bytearray ,
@@ -1763,6 +1779,20 @@ def deserialize_date(attr):
17631779 # This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
17641780 return isodate .parse_date (attr , defaultmonth = None , defaultday = None )
17651781
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+
17661796 @staticmethod
17671797 def deserialize_rfc (attr ):
17681798 """Deserialize RFC-1123 formatted string into Datetime object.
0 commit comments