Python dateutil.zoneinfo.gettz() Examples
The following are 30
code examples of dateutil.zoneinfo.gettz().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dateutil.zoneinfo
, or try the search function
.
Example #1
Source File: test_tz.py From plugin.video.emby with GNU General Public License v3.0 | 7 votes |
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))
Example #2
Source File: test_tz.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 6 votes |
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))
Example #4
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 6 votes |
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))
Example #5
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 6 votes |
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))
Example #6
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 6 votes |
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))
Example #7
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: test_tz.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
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))
Example #9
Source File: test_tz.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
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)
Example #10
Source File: test_tz.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
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))
Example #11
Source File: test_tz.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
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))
Example #12
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testGettz(self): # bug 892569 str(self.gettz('UTC'))
Example #13
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def gettz(self, tzname): # Actual time zone changes are handled by the _gettz_context function tzname_map = {'Australia/Sydney': self.TZ_AEST, 'America/Toronto': self.TZ_EST, 'America/New_York': self.TZ_EST} return tz.tzstr(tzname_map[tzname])
Example #14
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testTimeOnlyGettz(self): # gettz returns None tz_get = self.gettz('Europe/Minsk') self.assertIs(dt_time(13, 20, tzinfo=tz_get).utcoffset(), None)
Example #15
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testTimeOnlyGettzDST(self): # gettz returns None tz_get = self.gettz('Europe/Minsk') self.assertIs(dt_time(13, 20, tzinfo=tz_get).dst(), None)
Example #16
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testTimeOnlyGettzTzName(self): tz_get = self.gettz('Europe/Minsk') self.assertIs(dt_time(13, 20, tzinfo=tz_get).tzname(), None)
Example #17
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testGMTHasNoDaylight(self): # tz.tzstr("GMT+2") improperly considered daylight saving time. # Issue reported by Lennart Regebro. dt = datetime(2007, 8, 6, 4, 10) self.assertEqual(tz.gettz("GMT+2").dst(dt), timedelta(0))
Example #18
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testSupportAmbiguityFoldNaive(self): tzi = tz.gettz('US/Eastern') dt = datetime(2011, 11, 6, 1, 30) self.assertTrue(tz.datetime_ambiguous(dt, tz=tzi))
Example #19
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testPickleTzGettz(self): self.assertPicklable(tz.gettz('America/New_York'))
Example #20
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testSupportAmbiguityFoldAware(self): tzi = tz.gettz('US/Eastern') dt = datetime(2011, 11, 6, 1, 30, tzinfo=tzi) self.assertTrue(tz.datetime_ambiguous(dt))
Example #21
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def gettz(self, tzname): # Actual time zone changes are handled by the _gettz_context function return tz.tzlocal()
Example #22
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testExistsNaive(self): tzi = tz.gettz('Australia/Sydney') dt = datetime(2012, 10, 7, 10, 30) self.assertTrue(tz.datetime_exists(dt, tz=tzi))
Example #23
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
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)
Example #24
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
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)
Example #25
Source File: test_tz.py From plugin.video.emby with GNU General Public License v3.0 | 5 votes |
def gettz(self, tzname): raise NotImplementedError
Example #26
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def gettz(self, tzname): raise NotImplementedError
Example #27
Source File: test_imports.py From plugin.video.emby with GNU General Public License v3.0 | 5 votes |
def testZoneinfoStar(self): from dateutil.zoneinfo import gettz from dateutil.zoneinfo import gettz_db_metadata from dateutil.zoneinfo import rebuild zi_all = (gettz, gettz_db_metadata, rebuild) for var in zi_all: self.assertIsNot(var, None)
Example #28
Source File: test_tz.py From plugin.video.emby with GNU General Public License v3.0 | 5 votes |
def test_resolve_imaginary_monrovia(): # See GH #582 - When that is resolved, move this into test_resolve_imaginary tzi = tz.gettz('Africa/Monrovia') dt = datetime(1972, 1, 7, hour=0, minute=30, second=0, tzinfo=tzi) dt_exp = datetime(1972, 1, 7, hour=1, minute=14, second=30, tzinfo=tzi) dt_r = tz.resolve_imaginary(dt) assert dt_r == dt_exp assert dt_r.tzname() == dt_exp.tzname() assert dt_r.utcoffset() == dt_exp.utcoffset()
Example #29
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testExistsAware(self): tzi = tz.gettz('Australia/Sydney') dt = datetime(2012, 10, 7, 10, 30, tzinfo=tzi) self.assertTrue(tz.datetime_exists(dt))
Example #30
Source File: test_tz.py From bazarr with GNU General Public License v3.0 | 5 votes |
def testTimeOnlyFormatZ(self): tz_get = self.gettz('Europe/Minsk') t = dt_time(13, 20, tzinfo=tz_get) self.assertEqual(t.strftime('%H%M%Z'), '1320')