Skip to content

Commit

Permalink
Support unpickling instances having a numeric timezone like +0430.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdiary committed Apr 20, 2016
1 parent 595c397 commit 3ec477c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/DateTime/DateTime.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,11 @@ def _parse_args(self, *args, **kw):
# Seconds from epoch (gmt) and timezone
t, tz = args
ms = (t - math.floor(t))
tz = _TZINFO._zmap[tz.lower()]
try:
tz = _TZINFO._zmap[tz.lower()]
except KeyError:
if numericTimeZoneMatch(tz) is None:
raise DateTimeError('Unknown time zone: %s' % tz)
# Use integer arithmetic as much as possible.
s, d = _calcSD(t)
x = _calcDependentSecond(tz, t)
Expand Down
10 changes: 10 additions & 0 deletions src/DateTime/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ def test_pickle_with_tz(self):
for key in DateTime.__slots__:
self.assertEqual(getattr(dt, key), getattr(new, key))

def test_pickle_with_numerical_tz(self):
for dt_str in ('2007/01/02 12:34:56.789 +0300',
'2007/01/02 12:34:56.789 +0430',
'2007/01/02 12:34:56.789 -1234'):
dt = DateTime(dt_str)
data = pickle.dumps(dt, 1)
new = pickle.loads(data)
for key in DateTime.__slots__:
self.assertEqual(getattr(dt, key), getattr(new, key))

def test_pickle_with_micros(self):
dt = DateTime('2002/5/2 8:00:14.123 GMT+8')
data = pickle.dumps(dt, 1)
Expand Down

0 comments on commit 3ec477c

Please sign in to comment.