jsons.serializers.default_datetime   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 10
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A default_datetime_serializer() 0 16 1
1
from datetime import datetime
2
from typing import Optional
3
4
from jsons._datetime_impl import to_str, RFC3339_DATETIME_PATTERN
5
6
7
def default_datetime_serializer(obj: datetime,
8
                                *,
9
                                strip_microseconds: Optional[bool] = False,
10
                                **kwargs) -> str:
11
    """
12
    Serialize the given datetime instance to a string. It uses the RFC3339
13
    pattern. If datetime is a localtime, an offset is provided. If datetime is
14
    in UTC, the result is suffixed with a 'Z'.
15
    :param obj: the datetime instance that is to be serialized.
16
    :param strip_microseconds: determines whether microseconds should be
17
    omitted.
18
    :param kwargs: not used.
19
    :return: ``datetime`` as an RFC3339 string.
20
    """
21
    return to_str(obj, strip_microseconds, kwargs['fork_inst'],
22
                  RFC3339_DATETIME_PATTERN)
23