Commit 9c7ec24c authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

import part of DateTime's internal implementation to support timezone

like '+0100' etc.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18421 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8929da24
...@@ -27,12 +27,19 @@ ...@@ -27,12 +27,19 @@
############################################################################## ##############################################################################
from DateTime import DateTime as DateTimeKlass from DateTime import DateTime as DateTimeKlass
import math
from DateTime.DateTime import _calcSD, _calcDependentSecond, _calcYMDHMS
STATE_KEY = 'str' STATE_KEY = 'str'
def DateTime__setstate__(self, state): def DateTime__setstate__(self, state):
if isinstance(state, tuple): 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: elif len(state) != 1 or STATE_KEY not in state:
# For original pickle representation # For original pickle representation
self.__dict__.update(state) self.__dict__.update(state)
...@@ -46,3 +53,19 @@ def DateTime__getstate__(self): ...@@ -46,3 +53,19 @@ def DateTime__getstate__(self):
return (self._t, self._tz) return (self._t, self._tz)
DateTimeKlass.__getstate__ = DateTime__getstate__ 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]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment