Datetime Helpers

Helpers for datetime.

class proto.datetime_helpers.DatetimeWithNanoseconds(*args, **kw)[source]

Track nanosecond in addition to normal datetime attrs.

Nanosecond can be passed only as a keyword argument.

classmethod from_rfc3339(stamp)[source]

Parse RFC3339-compliant timestamp, preserving nanoseconds.

Parameters

stamp (str) – RFC3339 stamp, with up to nanosecond precision

Returns

an instance matching the timestamp string

Return type

DatetimeWithNanoseconds

Raises

ValueError – if stamp does not match the expected format

classmethod from_timestamp_pb(stamp)[source]

Parse RFC3339-compliant timestamp, preserving nanoseconds.

Parameters

stamp (Timestamp) – timestamp message

Returns

an instance matching the timestamp message

Return type

DatetimeWithNanoseconds

property nanosecond

nanosecond precision.

Type

Read-only

replace(*args, **kw)[source]

Return a date with the same value, except for those parameters given new values by whichever keyword arguments are specified. For example, if d == date(2002, 12, 31), then d.replace(day=26) == date(2002, 12, 26). NOTE: nanosecond and microsecond are mutually exclusive arguments.

rfc3339()[source]

Return an RFC3339-compliant timestamp.

Returns

Timestamp string according to RFC3339 spec.

Return type

(str)

timestamp_pb()[source]

Return a timestamp message.

Returns

Timestamp message

Return type

(Timestamp)