summaryrefslogtreecommitdiff
path: root/iso8601
diff options
context:
space:
mode:
authorMichael Twomey <michael.twomey@fieldaware.com>2013-10-17 18:24:22 +0100
committerMichael Twomey <michael.twomey@fieldaware.com>2013-10-17 18:24:22 +0100
commit2ebb90ea64858cf34d68ebdb915453e5325584a0 (patch)
tree93492e862bf377e4ccb26678e19b7d8592d8904b /iso8601
parent9c3f2b8518d5641973cd5ad45e26c0a980506bf9 (diff)
downloadpyiso8601-2ebb90ea64858cf34d68ebdb915453e5325584a0.tar.gz
Fix pickling / deepcopy of returned datetime objects
Thanks to fogathmann and john@openlearning.com Fixes #3
Diffstat (limited to 'iso8601')
-rw-r--r--iso8601/iso8601.py5
-rw-r--r--iso8601/test_iso8601.py4
2 files changed, 9 insertions, 0 deletions
diff --git a/iso8601/iso8601.py b/iso8601/iso8601.py
index b979f02..86c076b 100644
--- a/iso8601/iso8601.py
+++ b/iso8601/iso8601.py
@@ -82,6 +82,8 @@ class FixedOffset(tzinfo):
"""
def __init__(self, offset_hours, offset_minutes, name):
+ self.__offset_hours = offset_hours # Keep for later __getinitargs__
+ self.__offset_minutes = offset_minutes # Keep for later __getinitargs__
self.__offset = timedelta(hours=offset_hours, minutes=offset_minutes)
self.__name = name
@@ -96,6 +98,9 @@ class FixedOffset(tzinfo):
return other == self
return False
+ def __getinitargs__(self):
+ return (self.__offset_hours, self.__offset_minutes, self.__name)
+
def utcoffset(self, dt):
return self.__offset
diff --git a/iso8601/test_iso8601.py b/iso8601/test_iso8601.py
index 4a0b05c..a696038 100644
--- a/iso8601/test_iso8601.py
+++ b/iso8601/test_iso8601.py
@@ -1,7 +1,9 @@
# coding=UTF-8
from __future__ import absolute_import
+import copy
import datetime
+import pickle
import pytest
@@ -60,3 +62,5 @@ def test_parse_valid_date(valid_date, expected_datetime):
assert parsed.tzinfo == expected_datetime.tzinfo
assert parsed == expected_datetime
assert parsed.isoformat() == expected_datetime.isoformat()
+ copy.deepcopy(parsed) # ensure it's deep copy-able
+ pickle.dumps(parsed) # ensure it pickles \ No newline at end of file