[Erp5-report] r18421 - /erp5/trunk/products/ERP5Type/patches/DateTimePatch.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Dec 19 16:30:29 CET 2007
Author: kazuhiko
Date: Wed Dec 19 16:30:28 2007
New Revision: 18421
URL: http://svn.erp5.org?rev=18421&view=rev
Log:
import part of DateTime's internal implementation to support timezone
like '+0100' etc.
Modified:
erp5/trunk/products/ERP5Type/patches/DateTimePatch.py
Modified: erp5/trunk/products/ERP5Type/patches/DateTimePatch.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/DateTimePatch.py?rev=18421&r1=18420&r2=18421&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/DateTimePatch.py (original)
+++ erp5/trunk/products/ERP5Type/patches/DateTimePatch.py Wed Dec 19 16:30:28 2007
@@ -27,12 +27,19 @@
##############################################################################
from DateTime import DateTime as DateTimeKlass
+import math
+from DateTime.DateTime import _calcSD, _calcDependentSecond, _calcYMDHMS
STATE_KEY = 'str'
def DateTime__setstate__(self, state):
if isinstance(state, tuple):
- self._parse_args(*state)
+ t, tz = state
+ ms = (t - math.floor(t))
+ s,d = _calcSD(t)
+ x = _calcDependentSecond(tz, t)
+ yr, mo, dy, hr, mn, sc = _calcYMDHMS(x, ms)
+ self._parse_args(yr, mo, dy, hr, mn, sc, tz, t, d, s)
elif len(state) != 1 or STATE_KEY not in state:
# For original pickle representation
self.__dict__.update(state)
@@ -46,3 +53,19 @@
return (self._t, self._tz)
DateTimeKlass.__getstate__ = DateTime__getstate__
+
+if __name__ == '__main__':
+ for i in ('2007/01/02 12:34:56.789',
+ '2007/01/02 12:34:56.789 GMT+0200',
+ '2007/01/02 12:34:56.789 JST',
+ '2007/01/02 12:34:56.789 +0300',
+ '2007/01/02 12:34:56.789 +0430',
+ '2007/01/02 12:34:56.789 +1237',
+ ):
+ a = DateTimeKlass(i)
+ b = DateTimeKlass()
+ b.__setstate__(a.__getstate__())
+ print a, a.__dict__ == b.__dict__
+ for i in a.__dict__.keys():
+ if a.__dict__[i] != b.__dict__[i]:
+ print i, a.__dict__[i], b.__dict__[i]
More information about the Erp5-report
mailing list