summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Weis <gerhard.weis@gmail.com>2012-10-30 10:59:53 +1000
committerGerhard Weis <gerhard.weis@gmail.com>2012-10-30 10:59:53 +1000
commitafece50dc8260f8350a7e2f942886dc2b089bd47 (patch)
tree7dca64bfb1b76a6babdcafb62728c51483acd5a3
parentf16071ab3f7d16155e4b1a4c58ddb9016bd71dbe (diff)
downloadisodate-afece50dc8260f8350a7e2f942886dc2b089bd47.tar.gz
* make FixedOffset unpicklable
-rw-r--r--src/isodate/tests/test_pickle.py31
-rw-r--r--src/isodate/tzinfo.py24
2 files changed, 43 insertions, 12 deletions
diff --git a/src/isodate/tests/test_pickle.py b/src/isodate/tests/test_pickle.py
new file mode 100644
index 0000000..1475ee2
--- /dev/null
+++ b/src/isodate/tests/test_pickle.py
@@ -0,0 +1,31 @@
+import unittest
+import cPickle as pickle
+import isodate
+
+
+class TestPickle(unittest.TestCase):
+ '''
+ A test case template to parse an ISO datetime string into a
+ datetime object.
+ '''
+
+ def test_pickle(self):
+ '''
+ Parse an ISO datetime string and compare it to the expected value.
+ '''
+ dti = isodate.parse_datetime('2012-10-26T09:33+00:00')
+ pikl = pickle.dumps(dti, 2)
+ dto = pickle.loads(pikl)
+ self.assertEqual(dti, dto)
+
+
+def test_suite():
+ '''
+ Construct a TestSuite instance for all test cases.
+ '''
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestPickle))
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
diff --git a/src/isodate/tzinfo.py b/src/isodate/tzinfo.py
index ed6720f..820c88d 100644
--- a/src/isodate/tzinfo.py
+++ b/src/isodate/tzinfo.py
@@ -1,5 +1,5 @@
'''
-This module provides some datetime.tzinfo implementations.
+This module provides some datetime.tzinfo implementations.
All those classes are taken from the Python documentation.
'''
@@ -7,14 +7,14 @@ from datetime import timedelta, tzinfo
import time
ZERO = timedelta(0)
-# constant for zero time offset.
+# constant for zero time offset.
class Utc(tzinfo):
'''UTC
-
+
Universal time coordinated time zone.
'''
-
+
def utcoffset(self, dt):
'''
Return offset from UTC in minutes east of UTC, which is ZERO for UTC.
@@ -39,16 +39,16 @@ UTC = Utc()
class FixedOffset(tzinfo):
'''
A class building tzinfo objects for fixed-offset time zones.
-
- Note that FixedOffset(0, "UTC") is a different way to build a
- UTC tzinfo object.
+
+ Note that FixedOffset(0, 0, "UTC") or FixedOffset() is a different way to
+ build a UTC tzinfo object.
'''
-
- def __init__(self, offset_hours, offset_minutes, name):
+
+ def __init__(self, offset_hours=0, offset_minutes=0, name="UTC"):
'''
Initialise an instance with time offset and name.
The time offset should be positive for time zones east of UTC
- and negate for time zones west of UTC.
+ and negate for time zones west of UTC.
'''
self.__offset = timedelta(hours=offset_hours, minutes=offset_minutes)
self.__name = name
@@ -68,11 +68,11 @@ class FixedOffset(tzinfo):
def dst(self, dt):
'''
- Return the daylight saving time (DST) adjustment, in minutes east of
+ Return the daylight saving time (DST) adjustment, in minutes east of
UTC.
'''
return ZERO
-
+
def __repr__(self):
'''
Return nicely formatted repr string.