本文整理汇总了Python中dateutil.zoneinfo.gettz方法的典型用法代码示例。如果您正苦于以下问题:Python zoneinfo.gettz方法的具体用法?Python zoneinfo.gettz怎么用?Python zoneinfo.gettz使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dateutil.zoneinfo
的用法示例。
在下文中一共展示了zoneinfo.gettz方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFoldPositiveUTCOffset
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testFoldPositiveUTCOffset(self):
# Test that we can resolve ambiguous times
tzname = self._get_tzname('Australia/Sydney')
with self._gettz_context(tzname):
SYD = self.gettz(tzname)
t0_u = datetime(2012, 3, 31, 15, 30, tzinfo=tz.tzutc()) # AEST
t1_u = datetime(2012, 3, 31, 16, 30, tzinfo=tz.tzutc()) # AEDT
t0_syd0 = t0_u.astimezone(SYD)
t1_syd1 = t1_u.astimezone(SYD)
self.assertEqual(t0_syd0.replace(tzinfo=None),
datetime(2012, 4, 1, 2, 30))
self.assertEqual(t1_syd1.replace(tzinfo=None),
datetime(2012, 4, 1, 2, 30))
self.assertEqual(t0_syd0.utcoffset(), timedelta(hours=11))
self.assertEqual(t1_syd1.utcoffset(), timedelta(hours=10))
示例2: testGapPositiveUTCOffset
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testGapPositiveUTCOffset(self):
# Test that we don't have a problem around gaps.
tzname = self._get_tzname('Australia/Sydney')
with self._gettz_context(tzname):
SYD = self.gettz(tzname)
t0_u = datetime(2012, 10, 6, 15, 30, tzinfo=tz.tzutc()) # AEST
t1_u = datetime(2012, 10, 6, 16, 30, tzinfo=tz.tzutc()) # AEDT
t0 = t0_u.astimezone(SYD)
t1 = t1_u.astimezone(SYD)
self.assertEqual(t0.replace(tzinfo=None),
datetime(2012, 10, 7, 1, 30))
self.assertEqual(t1.replace(tzinfo=None),
datetime(2012, 10, 7, 3, 30))
self.assertEqual(t0.utcoffset(), timedelta(hours=10))
self.assertEqual(t1.utcoffset(), timedelta(hours=11))
示例3: testFoldNegativeUTCOffset
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testFoldNegativeUTCOffset(self):
# Test that we can resolve ambiguous times
tzname = self._get_tzname('America/Toronto')
with self._gettz_context(tzname):
TOR = self.gettz(tzname)
t0_u = datetime(2011, 11, 6, 5, 30, tzinfo=tz.tzutc())
t1_u = datetime(2011, 11, 6, 6, 30, tzinfo=tz.tzutc())
t0_tor = t0_u.astimezone(TOR)
t1_tor = t1_u.astimezone(TOR)
self.assertEqual(t0_tor.replace(tzinfo=None),
datetime(2011, 11, 6, 1, 30))
self.assertEqual(t1_tor.replace(tzinfo=None),
datetime(2011, 11, 6, 1, 30))
self.assertNotEqual(t0_tor.tzname(), t1_tor.tzname())
self.assertEqual(t0_tor.utcoffset(), timedelta(hours=-4.0))
self.assertEqual(t1_tor.utcoffset(), timedelta(hours=-5.0))
示例4: testGapNegativeUTCOffset
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testGapNegativeUTCOffset(self):
# Test that we don't have a problem around gaps.
tzname = self._get_tzname('America/Toronto')
with self._gettz_context(tzname):
TOR = self.gettz(tzname)
t0_u = datetime(2011, 3, 13, 6, 30, tzinfo=tz.tzutc())
t1_u = datetime(2011, 3, 13, 7, 30, tzinfo=tz.tzutc())
t0 = t0_u.astimezone(TOR)
t1 = t1_u.astimezone(TOR)
self.assertEqual(t0.replace(tzinfo=None),
datetime(2011, 3, 13, 1, 30))
self.assertEqual(t1.replace(tzinfo=None),
datetime(2011, 3, 13, 3, 30))
self.assertNotEqual(t0, t1)
self.assertEqual(t0.utcoffset(), timedelta(hours=-5.0))
self.assertEqual(t1.utcoffset(), timedelta(hours=-4.0))
示例5: testInZoneFoldEquality
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testInZoneFoldEquality(self):
# Two datetimes in the same zone are considered to be equal if their
# wall times are equal, even if they have different absolute times.
tzname = self._get_tzname('America/New_York')
with self._gettz_context(tzname):
NYC = self.gettz(tzname)
UTC = tz.tzutc()
dt0 = datetime(2011, 11, 6, 1, 30, tzinfo=NYC)
dt1 = tz.enfold(dt0, fold=1)
# Make sure these actually represent different times
self.assertNotEqual(dt0.astimezone(UTC), dt1.astimezone(UTC))
# Test that they compare equal
self.assertEqual(dt0, dt1)
示例6: __get_kiritimati_resolve_imaginary_test
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def __get_kiritimati_resolve_imaginary_test():
# In the 2018d release of the IANA database, the Kiritimati "imaginary day"
# data was corrected, so if the system zoneinfo is older than 2018d, the
# Kiritimati test will fail.
tzi = tz.gettz('Pacific/Kiritimati')
new_version = False
if not tz.datetime_exists(datetime(1995, 1, 1, 12, 30), tzi):
zif = zoneinfo.get_zonefile_instance()
if zif.metadata is not None:
new_version = zif.metadata['tzversion'] >= '2018d'
if new_version:
tzi = zif.get('Pacific/Kiritimati')
else:
new_version = True
if new_version:
dates = (datetime(1994, 12, 31, 12, 30), datetime(1995, 1, 1, 12, 30))
else:
dates = (datetime(1995, 1, 1, 12, 30), datetime(1995, 1, 2, 12, 30))
return (tzi, ) + dates
示例7: testFoldPositiveUTCOffset
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testFoldPositiveUTCOffset(self):
# Test that we can resolve ambiguous times
tzname = self._get_tzname('Australia/Sydney')
with self._gettz_context(tzname):
SYD0 = self.gettz(tzname)
SYD1 = self.gettz(tzname)
t0_u = datetime(2012, 3, 31, 15, 30, tzinfo=tz.tzutc()) # AEST
t1_u = datetime(2012, 3, 31, 16, 30, tzinfo=tz.tzutc()) # AEDT
# Using fresh tzfiles
t0_syd0 = t0_u.astimezone(SYD0)
t1_syd1 = t1_u.astimezone(SYD1)
self.assertEqual(t0_syd0.replace(tzinfo=None),
datetime(2012, 4, 1, 2, 30))
self.assertEqual(t1_syd1.replace(tzinfo=None),
datetime(2012, 4, 1, 2, 30))
self.assertEqual(t0_syd0.utcoffset(), timedelta(hours=11))
self.assertEqual(t1_syd1.utcoffset(), timedelta(hours=10))
示例8: testGapPositiveUTCOffset
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testGapPositiveUTCOffset(self):
# Test that we don't have a problem around gaps.
tzname = self._get_tzname('Australia/Sydney')
with self._gettz_context(tzname):
SYD0 = self.gettz(tzname)
SYD1 = self.gettz(tzname)
t0_u = datetime(2012, 10, 6, 15, 30, tzinfo=tz.tzutc()) # AEST
t1_u = datetime(2012, 10, 6, 16, 30, tzinfo=tz.tzutc()) # AEDT
# Using fresh tzfiles
t0 = t0_u.astimezone(SYD0)
t1 = t1_u.astimezone(SYD1)
self.assertEqual(t0.replace(tzinfo=None),
datetime(2012, 10, 7, 1, 30))
self.assertEqual(t1.replace(tzinfo=None),
datetime(2012, 10, 7, 3, 30))
self.assertEqual(t0.utcoffset(), timedelta(hours=10))
self.assertEqual(t1.utcoffset(), timedelta(hours=11))
示例9: testFoldNegativeUTCOffset
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testFoldNegativeUTCOffset(self):
# Test that we can resolve ambiguous times
tzname = self._get_tzname('America/Toronto')
with self._gettz_context(tzname):
# Calling fromutc() alters the tzfile object
TOR0 = self.gettz(tzname)
TOR1 = self.gettz(tzname)
t0_u = datetime(2011, 11, 6, 5, 30, tzinfo=tz.tzutc())
t1_u = datetime(2011, 11, 6, 6, 30, tzinfo=tz.tzutc())
# Using fresh tzfiles
t0_tor0 = t0_u.astimezone(TOR0)
t1_tor1 = t1_u.astimezone(TOR1)
self.assertEqual(t0_tor0.replace(tzinfo=None),
datetime(2011, 11, 6, 1, 30))
self.assertEqual(t1_tor1.replace(tzinfo=None),
datetime(2011, 11, 6, 1, 30))
self.assertEqual(t0_tor0.utcoffset(), timedelta(hours=-4.0))
self.assertEqual(t1_tor1.utcoffset(), timedelta(hours=-5.0))
示例10: testGapNegativeUTCOffset
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testGapNegativeUTCOffset(self):
# Test that we don't have a problem around gaps.
tzname = self._get_tzname('America/Toronto')
with self._gettz_context(tzname):
# Calling fromutc() alters the tzfile object
TOR0 = self.gettz(tzname)
TOR1 = self.gettz(tzname)
t0_u = datetime(2011, 3, 13, 6, 30, tzinfo=tz.tzutc())
t1_u = datetime(2011, 3, 13, 7, 30, tzinfo=tz.tzutc())
# Using fresh tzfiles
t0 = t0_u.astimezone(TOR0)
t1 = t1_u.astimezone(TOR1)
self.assertEqual(t0.replace(tzinfo=None),
datetime(2011, 3, 13, 1, 30))
self.assertEqual(t1.replace(tzinfo=None),
datetime(2011, 3, 13, 3, 30))
self.assertNotEqual(t0, t1)
self.assertEqual(t0.utcoffset(), timedelta(hours=-5.0))
self.assertEqual(t1.utcoffset(), timedelta(hours=-4.0))
示例11: testEqualAmbiguousComparison
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testEqualAmbiguousComparison(self):
tzname = self._get_tzname('Australia/Sydney')
with self._gettz_context(tzname):
SYD0 = self.gettz(tzname)
SYD1 = self.gettz(tzname)
t0_u = datetime(2012, 3, 31, 14, 30, tzinfo=tz.tzutc()) # AEST
t1_u = datetime(2012, 3, 31, 16, 30, tzinfo=tz.tzutc()) # AEDT
t0_syd0 = t0_u.astimezone(SYD0)
t0_syd1 = t0_u.astimezone(SYD1)
# This is considered an "inter-zone comparison" because it's an
# ambiguous datetime.
self.assertEqual(t0_syd0, t0_syd1)
示例12: gettz
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def gettz(self, tzname):
raise NotImplementedError
示例13: testFoldIndependence
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def testFoldIndependence(self):
tzname = self._get_tzname('America/New_York')
with self._gettz_context(tzname):
NYC = self.gettz(tzname)
UTC = tz.tzutc()
hour = timedelta(hours=1)
# Firmly 2015-11-01 0:30 EDT-4
pre_dst = datetime(2015, 11, 1, 0, 30, tzinfo=NYC)
# Ambiguous between 2015-11-01 1:30 EDT-4 and 2015-11-01 1:30 EST-5
in_dst = pre_dst + hour
in_dst_tzname_0 = in_dst.tzname() # Stash the tzname - EDT
# Doing the arithmetic in UTC creates a date that is unambiguously
# 2015-11-01 1:30 EDT-5
in_dst_via_utc = (pre_dst.astimezone(UTC) + 2*hour).astimezone(NYC)
# Make sure the dates are actually ambiguous
self.assertEqual(in_dst, in_dst_via_utc)
# Make sure we got the right folding behavior
self.assertNotEqual(in_dst_via_utc.tzname(), in_dst_tzname_0)
# Now check to make sure in_dst's tzname hasn't changed
self.assertEqual(in_dst_tzname_0, in_dst.tzname())
示例14: _test_ambiguous_time
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def _test_ambiguous_time(self, dt, tzid, ambiguous):
# This is a test to check that the individual is_ambiguous values
# on the _tzinfo subclasses work.
tzname = self._get_tzname(tzid)
with self._gettz_context(tzname):
tzi = self.gettz(tzname)
self.assertEqual(tz.datetime_ambiguous(dt, tz=tzi), ambiguous)
示例15: _test_imaginary_time
# 需要导入模块: from dateutil import zoneinfo [as 别名]
# 或者: from dateutil.zoneinfo import gettz [as 别名]
def _test_imaginary_time(self, dt, tzid, exists):
tzname = self._get_tzname(tzid)
with self._gettz_context(tzname):
tzi = self.gettz(tzname)
self.assertEqual(tz.datetime_exists(dt, tz=tzi), exists)