Commits

Michael Twomey  committed 65f8264

Fix pickling / deepcopy of returned datetime objects

Thanks to fogathmann and john@openlearning.com

Fixes #3

  • Participants
  • Parent commits bb1fd62

Comments (0)

Files changed (3)

 * Correctly raise ParseError for more invalid inputs (https://bitbucket.org/micktwomey/pyiso8601/issue/1/raise-parseerror-for-invalid-input) (thanks to manish.tomar)
 * Support more variations of ISO 8601 dates, times and time zone specs.
 * Fix microsecond rounding issues (https://bitbucket.org/micktwomey/pyiso8601/issue/2/roundoff-issues-when-parsing-decimal) (thanks to nielsenb@jetfuse.net)
+* Fix pickling and deepcopy of returned datetime objects (https://bitbucket.org/micktwomey/pyiso8601/issue/3/dates-returned-by-parse_date-do-not) (thanks to fogathmann and john@openlearning.com)
 
 0.1.4
 -----

File iso8601/iso8601.py

 
     """
     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
 
             return other == self
         return False
 
+    def __getinitargs__(self):
+        return (self.__offset_hours, self.__offset_minutes, self.__name)
+
     def utcoffset(self, dt):
         return self.__offset
 

File iso8601/test_iso8601.py

 # coding=UTF-8
 from __future__ import absolute_import
 
+import copy
 import datetime
+import pickle
 
 import pytest
 
     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