[Zope-Checkins] SVN: Zope/branches/ajung-DateTime-must-die-branch/lib/python/DateTime/DateTime.py we can create a datetime instance either from when loading the object from the ZODB

Andreas Jung andreas at andreas-jung.com
Sat Aug 25 10:24:03 EDT 2007


Log message for revision 79262:
  we can create a datetime instance either from when loading the object from the ZODB
  or within the constructor. Only one test failing so far (for a date with year > 10000).
  Mankind will be dead then....
  

Changed:
  U   Zope/branches/ajung-DateTime-must-die-branch/lib/python/DateTime/DateTime.py

-=-
Modified: Zope/branches/ajung-DateTime-must-die-branch/lib/python/DateTime/DateTime.py
===================================================================
--- Zope/branches/ajung-DateTime-must-die-branch/lib/python/DateTime/DateTime.py	2007-08-25 14:00:09 UTC (rev 79261)
+++ Zope/branches/ajung-DateTime-must-die-branch/lib/python/DateTime/DateTime.py	2007-08-25 14:24:03 UTC (rev 79262)
@@ -544,7 +544,19 @@
         """Return a new date-time object"""
 
         try:
-            return self._parse_args(*args, **kw)
+            result = self._parse_args(*args, **kw)
+
+
+            # try to create a datetime instance either from the timestamp
+            # or directly using the constructor (since self._t might be
+            # out-of-range for time_t
+
+            try:
+                self._D = datetime.fromtimestamp(self._t)
+            except:
+                self._D = datetime(self.year(), self.month(), self.day(),
+                                   self.hour(), self.minute(), self.second())
+            return result
         except (DateError, TimeError, DateTimeError):
             raise
         except:
@@ -1828,6 +1840,13 @@
             raise SyntaxError, (
                 'Not an ISO 8601 compliant date string: "%s"' % s)
 
+
+    def __setstate__(self, state):
+
+        self.__dict__.update(state)
+        if not state.has_key('_D'):
+            self._D = datetime.fromtimestamp(self._t)
+        
     def __parse_iso8601(self,s):
         """Parse an ISO 8601 compliant date.
 



More information about the Zope-Checkins mailing list