Commits

Phillip Alday committed 55952a0 Draft Merge

Bitbucket: Merged jurko/suds into default

Comments (0)

Files changed (2)

         self.tz.local = 0
 
 
+def get_local_timezone(tz):
+    """
+    Returns the local timezone offset based on local timezone and DST status.
+    """
+    offset_minutes = time.altzone if time.localtime().tm_isdst else time.timezone
+    return 0 - offset_minutes/60/60
+
+
 class Timezone:
     """
     Timezone object used to do TZ conversions
 
     pattern = re.compile('([zZ])|([\-\+][0-9]{2}:[0-9]{2})')
 
-    LOCAL = ( 0-time.timezone/60/60 ) + time.daylight
+    LOCAL = get_local_timezone
 
     def __init__(self, offset=None):
         if offset is None:
-            offset = self.LOCAL
+            offset = Timezone.LOCAL(self)
         self.local = offset
 
     @classmethod

tests/test_date_time.py

         self.equalsTimezone(6)
 
     def testUtcTimezone(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda tz: 0
         ref = datetime.date(1941, 12, 7)
         s = '%.4d-%.2d-%.2dZ' % (ref.year, ref.month, ref.day)
         xdate = Date()
         assert d == ref
 
     def equalsTimezone(self, tz):
-        Timezone.LOCAL = tz
+        Timezone.LOCAL = lambda cls: tz
         ref = datetime.date(1941, 12, 7)
         s = '%.4d-%.2d-%.2d%+.2d:00' % (ref.year, ref.month, ref.day, tz)
         xdate = Date()
         self.equalsTimezone(-6)
 
     def testUtcTimezone(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda cls: 0
         ref = datetime.time(10, 30, 22)
         s = '%.2d:%.2d:%.2dZ' % (ref.hour, ref.minute, ref.second)
         xtime = Time()
         assert t == ref
 
     def equalsTimezone(self, tz):
-        Timezone.LOCAL = tz
+        Timezone.LOCAL = lambda cls: tz
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, tz)
         xtime = Time()
         assert t == ref
 
     def testConvertNegativeToGreaterNegative(self):
-        Timezone.LOCAL = -6
+        Timezone.LOCAL = lambda tz: -6
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, -5)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertNegativeToLesserNegative(self):
-        Timezone.LOCAL = -5
+        Timezone.LOCAL = lambda tz: -5
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, -6)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertPositiveToGreaterPositive(self):
-        Timezone.LOCAL = 3
+        Timezone.LOCAL = lambda tz: 3
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, 2)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertPositiveToLesserPositive(self):
-        Timezone.LOCAL = 2
+        Timezone.LOCAL = lambda tz: 2
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, 3)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertPositiveToNegative(self):
-        Timezone.LOCAL = -6
+        Timezone.LOCAL = lambda tz: -6
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, 3)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertNegativeToPositive(self):
-        Timezone.LOCAL = 3
+        Timezone.LOCAL = lambda tz: 3
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, -6)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertNegativeToUtc(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda tz: 0
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, -6)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertPositiveToUtc(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda tz: 0
         ref = datetime.time(10, 30, 22)
         s = self.strTime(ref.hour, ref.minute, ref.second, 3)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertUtcToPositive(self):
-        Timezone.LOCAL = 3
+        Timezone.LOCAL = lambda tz: 3
         ref = datetime.time(10, 30, 22)
         s = '%.2d:%.2d:%.2dZ' % (ref.hour, ref.minute, ref.second)
         xtime = Time()
         assert ref.second == t.second
 
     def testConvertUtcToNegative(self):
-        Timezone.LOCAL = -6
+        Timezone.LOCAL = lambda tz: -6
         ref = datetime.time(10, 30, 22)
         s = '%.2d:%.2d:%.2dZ' % (ref.hour, ref.minute, ref.second)
         xtime = Time()
 class TestDateTime:
 
     def testSimple(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda tz: 0
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = '%.4d-%.2d-%.2dT%.2d:%.2d:%.2d' \
             % (ref.year,
         assert t == ref
 
     def testOverflow(self):
-        Timezone.LOCAL = -2
+        Timezone.LOCAL = lambda tz: -2
         ref = datetime.datetime(1, 1, 1, 0, 0, 0)
         s = '%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ' \
             % (ref.year,
         assert t == ref
 
     def testSimpleWithMicrosecond(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda tz: 0
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22, 454)
         s = '%.4d-%.2d-%.2dT%.2d:%.2d:%.2d.%.4d' \
             % (ref.year,
         self.equalsTimezone(-6)
 
     def testUtcTimezone(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda tz: 0
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = '%.4d-%.2d-%.2dT%.2d:%.2d:%.2d' \
             % (ref.year,
         assert t == ref
 
     def equalsTimezone(self, tz):
-        Timezone.LOCAL = tz
+        Timezone.LOCAL = lambda cls: tz
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert t == ref
 
     def testConvertNegativeToGreaterNegative(self):
-        Timezone.LOCAL = -6
+        Timezone.LOCAL = lambda tz: -6
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertNegativeToLesserNegative(self):
-        Timezone.LOCAL = -5
+        Timezone.LOCAL = lambda tz: -5
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertPositiveToGreaterPositive(self):
-        Timezone.LOCAL = 3
+        Timezone.LOCAL = lambda tz: 3
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertPositiveToLesserPositive(self):
-        Timezone.LOCAL = 2
+        Timezone.LOCAL = lambda tz: 2
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertPositiveToNegative(self):
-        Timezone.LOCAL = -6
+        Timezone.LOCAL = lambda tz: -6
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertNegativeToPositive(self):
-        Timezone.LOCAL = 3
+        Timezone.LOCAL = lambda tz: 3
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertNegativeToUtc(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda tz: 0
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertPositiveToUtc(self):
-        Timezone.LOCAL = 0
+        Timezone.LOCAL = lambda tz: 0
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertUtcToPositive(self):
-        Timezone.LOCAL = 3
+        Timezone.LOCAL = lambda tz: 3
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = '%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ' \
             % (ref.year,
         assert ref.second == t.second
 
     def testConvertUtcToNegative(self):
-        Timezone.LOCAL = -6
+        Timezone.LOCAL = lambda tz: -6
         ref = datetime.datetime(1941, 12, 7, 10, 30, 22)
         s = '%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ' \
             % (ref.year,
         assert ref.second == t.second
 
     def testConvertNegativeToGreaterNegativeAndPreviousDay(self):
-        Timezone.LOCAL = -6
+        Timezone.LOCAL = lambda tz: -6
         ref = datetime.datetime(1941, 12, 7, 0, 30, 22)
         s = self.strDateTime(
                 ref.year,
         assert ref.second == t.second
 
     def testConvertNegativeToLesserNegativeAndNextDay(self):
-        Timezone.LOCAL = -5
+        Timezone.LOCAL = lambda tz: -5
         ref = datetime.datetime(1941, 12, 7, 23, 30, 22)
         s = self.strDateTime(
                 ref.year,