Exemple #1
0
    def test_ambiguous(self):
        date = SimpleDate(1234567890, tz=utc)
        assert str(date) == '2009-02-13 23:31:30.000000 UTC', str(date)
        with self.assertRaisesRegex(AmbiguousTimezone, '3 distinct'):
            DEFAULT_TZ_FACTORY.search(('Australia/NSW', 'Australia/Queensland', 'EST'), datetime=date.datetime, debug=True)

        tz_nsw = timezone('Australia/NSW')
        offset_nsw = tzinfo_utcoffset(tz_nsw, date.datetime)
        # /usr/sbin/zdump -v -c 2014 Australia/NSW
        # Australia/NSW  Sat Oct  4 16:00:00 2008 UTC = Sun Oct  5 03:00:00 2008 EST isdst=1 gmtoff=39600
        # Australia/NSW  Sat Apr  4 15:59:59 2009 UTC = Sun Apr  5 02:59:59 2009 EST isdst=1 gmtoff=39600
        assert offset_nsw == dt.timedelta(seconds=39600)

        tz_qns = timezone('Australia/Queensland')
        offset_qns = tzinfo_utcoffset(tz_qns, date.datetime)
        # /usr/sbin/zdump -v Australia/Queensland
        # Australia/Queensland  Sat Feb 29 16:00:00 1992 UTC = Sun Mar  1 02:00:00 1992 EST isdst=0 gmtoff=36000
        # (last entry)
        assert offset_qns == dt.timedelta(seconds=36000)

        tz_est = timezone('EST')
        offset_est = tzinfo_utcoffset(tz_est, date.datetime)
        # zdump shows no transitions, but this is used in the USA so we expect
        # it to differ from the Australian ones
        assert offset_nsw != offset_qns != offset_est != offset_nsw
Exemple #2
0
 def test_country(self):
     with self.assertRaisesRegex(AmbiguousTimezone, "2 distinct timezones"):
         DEFAULT_TZ_FACTORY.search(datetime=dt.datetime(2012, 5, 19, 12), country='CL', debug=DEBUG)
     tz = DEFAULT_TZ_FACTORY.search('EDT', datetime=dt.datetime(2012, 5, 19, 12), country='US', debug=DEBUG)
     assert repr(tz) == "SingleInstantTz(datetime.timedelta(-1, 72000), 'EDT', datetime.datetime(2012, 5, 19, 16, 0, tzinfo=<UTC>))", repr(tz)
     tz = DEFAULT_TZ_FACTORY.search('EDT', datetime=dt.datetime(2012, 5, 19, 12), debug=DEBUG)
     assert repr(tz) == "SingleInstantTz(datetime.timedelta(-1, 72000), 'EDT', datetime.datetime(2012, 5, 19, 16, 0, tzinfo=<UTC>))", repr(tz)
Exemple #3
0
 def test_both(self):
     date = SimpleDate(2013, 2, 2, tz='CLST', debug=DEBUG)
     tz = DEFAULT_TZ_FACTORY.search('EST', country='US', datetime=date)
     target = date.datetime - date.datetime.utcoffset()
     target = target.replace(tzinfo=tz)
     target = tz.fromutc(target)
     assert str(target) == '2013-02-01 22:00:00-05:00', str(target)
     target = date.convert(tz)
     assert str(target) == '2013-02-01 22:00:00.000000 EST', str(target)
Exemple #4
0
 def test_to2(self):
     date = SimpleDate(2013, 6, 2, tz=timezone('America/Santiago'), debug=DEBUG)
     tz = DEFAULT_TZ_FACTORY.search('EDT', country='US', datetime=date, debug=DEBUG)
     target = date.datetime - date.datetime.utcoffset()
     target = target.replace(tzinfo=tz)
     target = tz.fromutc(target)
     assert str(target) == '2013-06-02 00:00:00-04:00', str(target)
     target = date.convert(tz)
     assert str(target) == '2013-06-02 00:00:00.000000 EDT', str(target)
Exemple #5
0
 def test_to(self):
     date = SimpleDate(2013, 2, 2, tz=timezone(u'America/Santiago'), debug=DEBUG)
     tz = DEFAULT_TZ_FACTORY.search(u'EST', country=u'US', datetime=date, debug=DEBUG)
     target = date.datetime - date.datetime.utcoffset()
     target = target.replace(tzinfo=tz)
     target = tz.fromutc(target)
     assert unicode(target) == u'2013-02-01 22:00:00-05:00', unicode(target)
     target = date.convert(tz)
     assert unicode(target) == u'2013-02-01 22:00:00.000000 EST', unicode(target)
Exemple #6
0
 def test_epoch0_bug(self):
     with self.assertRaisesRegex(SimpleDateError, "No timezone found"):
         tz = DEFAULT_TZ_FACTORY.search('CLT', datetime=dt.datetime(1970, 1, 1), debug=DEBUG)
     tz = DEFAULT_TZ_FACTORY.search('CLST', datetime=dt.datetime(1970, 1, 1), debug=DEBUG)