Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))), False,
'c07819323031332d30332d32315432323a30343a30302b30323a3030'),
(datetime(2013, 3, 21, 20, 4, 0), False, 'c074323031332d30332d32315432303a30343a30305a'),
(datetime(2013, 3, 21, 20, 4, 0, tzinfo=timezone.utc), True, 'c11a514b67b0'),
(datetime(2013, 3, 21, 20, 4, 0, 123456, tzinfo=timezone.utc), True, 'c1fb41d452d9ec07e6b4'),
(datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))), True, 'c11a514b67b0')
], ids=[
'datetime/utc',
'datetime+micro/utc',
'datetime/eet',
'naive',
'timestamp/utc',
'timestamp+micro/utc',
'timestamp/eet'
])
def test_datetime(impl, value, as_timestamp, expected):
expected = unhexlify(expected)
datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2)))),
('c11a514b67b0', datetime(2013, 3, 21, 20, 4, 0, tzinfo=timezone.utc)),
('c11a514b67b0', datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))))
], ids=['datetime/utc', 'datetime+micro/utc', 'datetime/eet', 'timestamp/utc', 'timestamp/eet'])
def test_datetime(impl, payload, expected):
decoded = impl.loads(unhexlify(payload))
assert decoded == expected
(datetime(2013, 3, 21, 20, 4, 0, tzinfo=timezone.utc), True, 'c11a514b67b0'),
(datetime(2013, 3, 21, 20, 4, 0, 123456, tzinfo=timezone.utc), True, 'c1fb41d452d9ec07e6b4'),
(datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))), True, 'c11a514b67b0')
], ids=[
'datetime/utc',
'datetime+micro/utc',
'datetime/eet',
'naive',
'timestamp/utc',
'timestamp+micro/utc',
'timestamp/eet'
])
def test_datetime(impl, value, as_timestamp, expected):
expected = unhexlify(expected)
assert impl.dumps(value, datetime_as_timestamp=as_timestamp, timezone=timezone.utc) == expected
value = self._decode()
match = timestamp_re.match(value)
if match:
(
year,
month,
day,
hour,
minute,
second,
micro,
offset_h,
offset_m,
) = match.groups()
if offset_h:
tz = timezone(timedelta(hours=int(offset_h), minutes=int(offset_m)))
else:
tz = timezone.utc
return self.set_shareable(datetime(
int(year), int(month), int(day),
int(hour), int(minute), int(second), int(micro or 0), tz))
else:
raise CBORDecodeValueError(
'invalid datetime string: {!r}'.format(value))