Example #1
0
    def test_datetime_timezone(self):
        class FixedNoDst(datetime.tzinfo):
            'A timezone info with fixed offset, not DST'

            def utcoffset(self, dt):
                return datetime.timedelta(hours=2, minutes=30)

            def dst(self, dt):
                return None

        fixed_no_dst = FixedNoDst()

        class Fixed(FixedNoDst):
            'A timezone info with DST'

            def dst(self, dt):
                return datetime.timedelta(hours=3, minutes=15)

        fixed = Fixed()

        d = datetime.datetime.now().replace(tzinfo=fixed_no_dst)
        timezone = _timezone(_timedelta_to_seconds(fixed_no_dst.\
                                                   utcoffset(None)))
        eq_(rfc3339(d), d.strftime('%Y-%m-%dT%H:%M:%S') + timezone)

        d = datetime.datetime.now().replace(tzinfo=fixed)
        timezone = _timezone(_timedelta_to_seconds(fixed.dst(None)))
        eq_(rfc3339(d), d.strftime('%Y-%m-%dT%H:%M:%S') + timezone)
Example #2
0
    def test_datetime_timezone(self):

        class FixedNoDst(datetime.tzinfo):
            'A timezone info with fixed offset, not DST'

            def utcoffset(self, dt):
                return datetime.timedelta(hours=2, minutes=30)

            def dst(self, dt):
                return None

        fixed_no_dst = FixedNoDst()

        class Fixed(FixedNoDst):
            'A timezone info with DST'

            def dst(self, dt):
                return datetime.timedelta(hours=3, minutes=15)

        fixed = Fixed()

        d = datetime.datetime.now().replace(tzinfo=fixed_no_dst)
        timezone = _timezone(_timedelta_to_seconds(fixed_no_dst.\
                                                   utcoffset(None)))
        eq_(rfc3339(d),
                         d.strftime('%Y-%m-%dT%H:%M:%S') + timezone)

        d = datetime.datetime.now().replace(tzinfo=fixed)
        timezone = _timezone(_timedelta_to_seconds(fixed.dst(None)))
        eq_(rfc3339(d),
                         d.strftime('%Y-%m-%dT%H:%M:%S') + timezone)
Example #3
0
 def setUp(self):
     local_utcoffset = _utc_offset(datetime.datetime.now(), True)
     self.local_utcoffset = datetime.timedelta(seconds=local_utcoffset)
     self.local_timezone = _timezone(local_utcoffset)
Example #4
0
 def setUp(self):
     local_utcoffset = _utc_offset(datetime.datetime.now(), True)
     self.local_utcoffset = datetime.timedelta(seconds=local_utcoffset)
     self.local_timezone = _timezone(local_utcoffset)