Skip to content

Commit 7eff95a

Browse files
committed
Fix issue2551128 - Impossible to validate a user with unknown timezone
Raise KeyError when an unrecognized timezones is passed to pytz. (patch Cedric Krier, test John Rouillard)
1 parent 961d73b commit 7eff95a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ Fixed:
8585
this now requires that setuptools be installed. (Patch by John
8686
Kristensen (jerrykan); additional doc changes (upgrade.txt,
8787
RELEASE.txt) John Rouillard)
88+
- issue2551128 - Impossible to validate a user with unknown timezone
89+
Raise KeyError when an unrecognized timezones is passed to
90+
pytz. (patch Cedric Krier, test John Rouillard)
8891

8992
Features:
9093
- issue2550522 - Add 'filter' command to command-line

roundup/date.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ def get_timezone(tz):
146146
return SimpleTimezone(utcoffset)
147147
# tz is a timezone name
148148
if pytz:
149-
return pytz.timezone(tz)
150-
elif tz == "UTC":
149+
try:
150+
return pytz.timezone(tz)
151+
except pytz.exceptions.UnknownTimeZoneError:
152+
pass
153+
154+
if tz == "UTC":
151155
return UTC
152156
elif tz in _tzoffsets:
153157
return SimpleTimezone(_tzoffsets[tz], tz)

test/test_dates.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,16 @@ def testTZ(self):
495495
date = Date(date, tz)
496496
ae(str(date), '2006-01-01.11:00:00')
497497

498+
def testUnrecognizedTimezone(self):
499+
'''Unrecognize timezone should raise key error'''
500+
501+
# unrecognized timezone
502+
tz = 'Zoot'
503+
504+
with self.assertRaises(KeyError) as cm:
505+
date = Date('2006-04-04.12:00:00', tz)
506+
507+
self.assertEqual(cm.exception.args, ('Zoot',))
498508

499509
class RangeTestCase(unittest.TestCase):
500510

0 commit comments

Comments
 (0)