mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-30155: Add macros to get tzinfo from datetime instances (GH-21633)
Add PyDateTime_DATE_GET_TZINFO() and PyDateTime_TIME_GET_TZINFO() macros.
This commit is contained in:
parent
9c4eac7f02
commit
2e4dd336e5
8 changed files with 46 additions and 17 deletions
|
@ -5991,30 +5991,36 @@ class CapiTest(unittest.TestCase):
|
|||
|
||||
for klass in [datetime, DateTimeSubclass]:
|
||||
for args in [(1993, 8, 26, 22, 12, 55, 99999),
|
||||
(1993, 8, 26, 22, 12, 55, 99999)]:
|
||||
(1993, 8, 26, 22, 12, 55, 99999,
|
||||
timezone.utc)]:
|
||||
d = klass(*args)
|
||||
with self.subTest(cls=klass, date=args):
|
||||
hour, minute, second, microsecond = _testcapi.PyDateTime_DATE_GET(d)
|
||||
hour, minute, second, microsecond, tzinfo = \
|
||||
_testcapi.PyDateTime_DATE_GET(d)
|
||||
|
||||
self.assertEqual(hour, d.hour)
|
||||
self.assertEqual(minute, d.minute)
|
||||
self.assertEqual(second, d.second)
|
||||
self.assertEqual(microsecond, d.microsecond)
|
||||
self.assertIs(tzinfo, d.tzinfo)
|
||||
|
||||
def test_PyDateTime_TIME_GET(self):
|
||||
class TimeSubclass(time):
|
||||
pass
|
||||
|
||||
for klass in [time, TimeSubclass]:
|
||||
for args in [(12, 30, 20, 10), (12, 30, 20, 10)]:
|
||||
for args in [(12, 30, 20, 10),
|
||||
(12, 30, 20, 10, timezone.utc)]:
|
||||
d = klass(*args)
|
||||
with self.subTest(cls=klass, date=args):
|
||||
hour, minute, second, microsecond = _testcapi.PyDateTime_TIME_GET(d)
|
||||
hour, minute, second, microsecond, tzinfo = \
|
||||
_testcapi.PyDateTime_TIME_GET(d)
|
||||
|
||||
self.assertEqual(hour, d.hour)
|
||||
self.assertEqual(minute, d.minute)
|
||||
self.assertEqual(second, d.second)
|
||||
self.assertEqual(microsecond, d.microsecond)
|
||||
self.assertIs(tzinfo, d.tzinfo)
|
||||
|
||||
def test_timezones_offset_zero(self):
|
||||
utc0, utc1, non_utc = _testcapi.get_timezones_offset_zero()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue