我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用dateutil.tz.tzstr()。
def testTzAll(self): from dateutil.tz import tzutc from dateutil.tz import tzoffset from dateutil.tz import tzlocal from dateutil.tz import tzfile from dateutil.tz import tzrange from dateutil.tz import tzstr from dateutil.tz import tzical from dateutil.tz import gettz from dateutil.tz import tzwin from dateutil.tz import tzwinlocal tz_all = ["tzutc", "tzoffset", "tzlocal", "tzfile", "tzrange", "tzstr", "tzical", "gettz"] tz_all += ["tzwin", "tzwinlocal"] if sys.platform.startswith("win") else [] lvars = locals() for var in tz_all: self.assertIsNot(lvars[var], None)
def testStrInequality(self): TZS1 = tz.tzstr('EST5EDT4') # Standard abbreviation different TZS2 = tz.tzstr('ET5EDT4') self.assertNotEqual(TZS1, TZS2) # DST abbreviation different TZS3 = tz.tzstr('EST5EMT') self.assertNotEqual(TZS1, TZS3) # STD offset different TZS4 = tz.tzstr('EST4EDT4') self.assertNotEqual(TZS1, TZS4) # DST offset different TZS5 = tz.tzstr('EST5EDT3') self.assertNotEqual(TZS1, TZS5)
def testRangeCmp1(self): self.assertEqual(tz.tzstr("EST5EDT"), tz.tzrange("EST", -18000, "EDT", -14400, relativedelta(hours=+2, month=4, day=1, weekday=SU(+1)), relativedelta(hours=+1, month=10, day=31, weekday=SU(-1))))
def testRangeCmp2(self): self.assertEqual(tz.tzstr("EST5EDT"), tz.tzrange("EST", -18000, "EDT"))
def testBrokenIsDstHandling(self): # tzrange._isdst() was using a date() rather than a datetime(). # Issue reported by Lennart Regebro. dt = datetime(2007, 8, 6, 4, 10, tzinfo=tz.tzutc()) self.assertEqual(dt.astimezone(tz=tz.gettz("GMT+2")), datetime(2007, 8, 6, 6, 10, tzinfo=tz.tzstr("GMT+2")))
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])
def testStrEnd1(self): self.assertEqual(datetime(2003, 10, 26, 0, 59, tzinfo=tz.tzstr("EST5EDT")).tzname(), "EDT") end = tz.enfold(datetime(2003, 10, 26, 1, 00, tzinfo=tz.tzstr("EST5EDT")), fold=1) self.assertEqual(end.tzname(), "EST")
def testStrStart2(self): s = "EST5EDT,4,0,6,7200,10,0,26,7200,3600" self.assertEqual(datetime(2003, 4, 6, 1, 59, tzinfo=tz.tzstr(s)).tzname(), "EST") self.assertEqual(datetime(2003, 4, 6, 2, 00, tzinfo=tz.tzstr(s)).tzname(), "EDT")
def testStrEnd2(self): s = "EST5EDT,4,0,6,7200,10,0,26,7200,3600" self.assertEqual(datetime(2003, 10, 26, 0, 59, tzinfo=tz.tzstr(s)).tzname(), "EDT") end = tz.enfold(datetime(2003, 10, 26, 1, 00, tzinfo=tz.tzstr(s)), fold=1) self.assertEqual(end.tzname(), "EST")
def testStrStart3(self): s = "EST5EDT,4,1,0,7200,10,-1,0,7200,3600" self.assertEqual(datetime(2003, 4, 6, 1, 59, tzinfo=tz.tzstr(s)).tzname(), "EST") self.assertEqual(datetime(2003, 4, 6, 2, 00, tzinfo=tz.tzstr(s)).tzname(), "EDT")
def testStrEnd3(self): s = "EST5EDT,4,1,0,7200,10,-1,0,7200,3600" self.assertEqual(datetime(2003, 10, 26, 0, 59, tzinfo=tz.tzstr(s)).tzname(), "EDT") end = tz.enfold(datetime(2003, 10, 26, 1, 00, tzinfo=tz.tzstr(s)), fold=1) self.assertEqual(end.tzname(), "EST")
def testStrEnd4(self): s = "EST5EDT4,M4.1.0/02:00:00,M10-5-0/02:00" self.assertEqual(datetime(2003, 10, 26, 0, 59, tzinfo=tz.tzstr(s)).tzname(), "EDT") end = tz.enfold(datetime(2003, 10, 26, 1, 00, tzinfo=tz.tzstr(s)), fold=1) self.assertEqual(end.tzname(), "EST")
def testStrStart5(self): s = "EST5EDT4,95/02:00:00,298/02:00" self.assertEqual(datetime(2003, 4, 6, 1, 59, tzinfo=tz.tzstr(s)).tzname(), "EST") self.assertEqual(datetime(2003, 4, 6, 2, 00, tzinfo=tz.tzstr(s)).tzname(), "EDT")
def testStrEnd5(self): s = "EST5EDT4,95/02:00:00,298/02" self.assertEqual(datetime(2003, 10, 26, 0, 59, tzinfo=tz.tzstr(s)).tzname(), "EDT") end = tz.enfold(datetime(2003, 10, 26, 1, 00, tzinfo=tz.tzstr(s)), fold=1) self.assertEqual(end.tzname(), "EST")
def testStrStart6(self): s = "EST5EDT4,J96/02:00:00,J299/02:00" self.assertEqual(datetime(2003, 4, 6, 1, 59, tzinfo=tz.tzstr(s)).tzname(), "EST") self.assertEqual(datetime(2003, 4, 6, 2, 00, tzinfo=tz.tzstr(s)).tzname(), "EDT")
def testStrEnd6(self): s = "EST5EDT4,J96/02:00:00,J299/02" self.assertEqual(datetime(2003, 10, 26, 0, 59, tzinfo=tz.tzstr(s)).tzname(), "EDT") end = tz.enfold(datetime(2003, 10, 26, 1, 00, tzinfo=tz.tzstr(s)), fold=1) self.assertEqual(end.tzname(), "EST")
def testStrCmp1(self): self.assertEqual(tz.tzstr("EST5EDT"), tz.tzstr("EST5EDT4,M4.1.0/02:00:00,M10-5-0/02:00"))
def testStrCmp2(self): # TODO: This is parsing the default arguments. self.assertEqual(tz.tzstr("EST5EDT"), tz.tzstr("EST5EDT,4,1,0,7200,10,-1,0,7200,3600"))
def testStrInequalityStartEnd(self): TZS1 = tz.tzstr('EST5EDT4') # Start delta different TZS2 = tz.tzstr('EST5EDT4,M4.2.0/02:00:00,M10-5-0/02:00') self.assertNotEqual(TZS1, TZS2) # End delta different TZS3 = tz.tzstr('EST5EDT4,M4.2.0/02:00:00,M11-5-0/02:00') self.assertNotEqual(TZS1, TZS3)
def testPosixOffset(self): TZ1 = tz.tzstr('UTC-3') self.assertEqual(datetime(2015, 1, 1, tzinfo=TZ1).utcoffset(), timedelta(hours=-3)) TZ2 = tz.tzstr('UTC-3', posix_offset=True) self.assertEqual(datetime(2015, 1, 1, tzinfo=TZ2).utcoffset(), timedelta(hours=+3))
def testTzStrRepr(self): TZS1 = tz.tzstr('EST5EDT4') TZS2 = tz.tzstr('EST') self.assertEqual(repr(TZS1), "tzstr(" + repr('EST5EDT4') + ")") self.assertEqual(repr(TZS2), "tzstr(" + repr('EST') + ")")
def testTzStrFailure(self): with self.assertRaises(ValueError): tz.tzstr('InvalidString;439999')
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))
def testGMTOffset(self): # GMT and UTC offsets have inverted signal when compared to the # usual TZ variable handling. dt = datetime(2007, 8, 6, 4, 10, tzinfo=tz.tzutc()) self.assertEqual(dt.astimezone(tz=tz.tzstr("GMT+2")), datetime(2007, 8, 6, 6, 10, tzinfo=tz.tzstr("GMT+2"))) self.assertEqual(dt.astimezone(tz=tz.gettz("UTC-2")), datetime(2007, 8, 6, 2, 10, tzinfo=tz.tzstr("UTC-2")))