| Conditions | 3 |
| Total Lines | 18 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from datetime import datetime |
||
| 7 | def default_datetime_serializer(obj: datetime, |
||
| 8 | strip_microseconds: Optional[bool] = True, |
||
| 9 | **kwargs) -> str: |
||
| 10 | """ |
||
| 11 | Serialize the given datetime instance to a string. It uses the RFC3339 |
||
| 12 | pattern. If datetime is a localtime, an offset is provided. If datetime is |
||
| 13 | in UTC, the result is suffixed with a 'Z'. |
||
| 14 | :param obj: the datetime instance that is to be serialized. |
||
| 15 | :param strip_microseconds: determines whether microseconds should be |
||
| 16 | omitted. |
||
| 17 | :param kwargs: not used. |
||
| 18 | :return: ``datetime`` as an RFC3339 string. |
||
| 19 | """ |
||
| 20 | pattern = RFC3339_DATETIME_PATTERN |
||
| 21 | offset = get_offset_str(obj) |
||
| 22 | if not strip_microseconds and obj.microsecond: |
||
| 23 | pattern += '.%f' |
||
| 24 | return obj.strftime("{}{}".format(pattern, offset)) |
||
| 25 |