Skip to content

Commit

Permalink
Merge pull request #4 from fdiary/fix_unpickle_numeric_timezone
Browse files Browse the repository at this point in the history
Support unpickling instances having a numeric timezone like +0430.
  • Loading branch information
tseaver committed Apr 20, 2016
2 parents 077d51c + 3ec477c commit 766bad5
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
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
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 766bad5

Please sign in to comment.