Skip to content

Commit ea921de

Browse files
corderysdispater
authored andcommitted
Corrected 'z' timezone parsing in from_format to allow underscores (#268)
Ex: America/New_York. Expanded tests to ensure parsing of all symbols found in pendulum.timezones.
1 parent 0e91f16 commit ea921de

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pendulum/formatting/formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+"
3333
"|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}"
3434
)
35-
_MATCH_TIMEZONE = "[A-za-z0-9-+]+(/[A-Za-z0-9-+]+)?"
35+
_MATCH_TIMEZONE = "[A-za-z0-9-+]+(/[A-Za-z0-9-+_]+)?"
3636

3737

3838
class Formatter:

tests/datetime/test_from_format.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ def test_from_format_with_millis():
9292
"1975-12-25T14:15:16-05:00",
9393
None,
9494
),
95+
(
96+
"1975-12-25T14:15:16 America/New_York",
97+
"YYYY-MM-DDTHH:mm:ss z",
98+
"1975-12-25T14:15:16-05:00",
99+
None,
100+
),
101+
(
102+
"1975-12-25T14:15:16 Africa/Porto-Novo",
103+
"YYYY-MM-DDTHH:mm:ss z",
104+
"1975-12-25T14:15:16+01:00",
105+
None,
106+
),
107+
(
108+
"1975-12-25T14:15:16 Etc/GMT+0",
109+
"YYYY-MM-DDTHH:mm:ss z",
110+
"1975-12-25T14:15:16+00:00",
111+
None,
112+
),
113+
(
114+
"1975-12-25T14:15:16 W-SU",
115+
"YYYY-MM-DDTHH:mm:ss z",
116+
"1975-12-25T14:15:16+03:00",
117+
None,
118+
),
95119
],
96120
)
97121
def test_from_format(text, fmt, expected, now):

0 commit comments

Comments
 (0)