| Conditions | 2 |
| Total Lines | 18 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import datetime |
||
| 7 | def default_datetime_deserializer(obj: str, |
||
| 8 | cls: type = datetime, |
||
| 9 | **kwargs) -> datetime: |
||
| 10 | """ |
||
| 11 | Deserialize a string with an RFC3339 pattern to a datetime instance. |
||
| 12 | :param obj: the string that is to be deserialized. |
||
| 13 | :param cls: not used. |
||
| 14 | :param kwargs: not used. |
||
| 15 | :return: a ``datetime.datetime`` instance. |
||
| 16 | """ |
||
| 17 | pattern = RFC3339_DATETIME_PATTERN |
||
| 18 | if '.' in obj: |
||
| 19 | pattern += '.%f' |
||
| 20 | # strptime allows a fraction of length 6, so trip the rest (if exists). |
||
| 21 | regex_pattern = re.compile(r'(\.[0-9]+)') |
||
| 22 | frac = regex_pattern.search(obj).group() |
||
| 23 | obj = obj.replace(frac, frac[0:7]) |
||
| 24 | return get_datetime_inst(obj, pattern) |
||
| 25 |