Skip to content

Commit bb69247

Browse files
committed
Merge branch 'tersers-master'
2 parents 033f675 + e8dc944 commit bb69247

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Fixed `from_format()` not recognizing input strings when the specified pattern had escaped elements.
88
- Fixed missing `x` token for string formatting.
99
- Fixed reading timezone files.
10+
- Added support for parsing padded 2-digit days of the month with `from_format()`
1011

1112

1213
## [2.0.3] - 2018-07-30

pendulum/formatting/formatter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
_MATCH_4 = "\d{4}"
1818
_MATCH_6 = "[+-]?\d{6}"
1919
_MATCH_1_TO_2 = "\d\d?"
20+
_MATCH_1_TO_2_LEFT_PAD = "[0-9 ]\d?"
2021
_MATCH_1_TO_3 = "\d{1,3}"
2122
_MATCH_1_TO_4 = "\d{1,4}"
2223
_MATCH_1_TO_6 = "[+-]?\d{1,6}"
@@ -157,7 +158,7 @@ class Formatter:
157158
"MMM": _MATCH_WORD,
158159
"MMMM": _MATCH_WORD,
159160
"D": _MATCH_1_TO_2,
160-
"DD": (_MATCH_1_TO_2, _MATCH_2),
161+
"DD": (_MATCH_1_TO_2_LEFT_PAD, _MATCH_2),
161162
"DDD": _MATCH_1_TO_3,
162163
"DDDD": _MATCH_3,
163164
"dddd": _MATCH_WORD,

tests/datetime/test_from_format.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ def test_from_format_with_millis():
4242
assert_datetime(d, 1975, 5, 21, 22, 32, 11, 123456)
4343

4444

45+
def test_from_format_with_padded_day():
46+
d = pendulum.from_format("Apr 2 12:00:00 2020 GMT", "MMM DD HH:mm:ss YYYY z")
47+
assert_datetime(d, 2020, 4, 2, 12)
48+
49+
50+
def test_from_format_with_invalid_padded_day():
51+
with pytest.raises(ValueError):
52+
d = pendulum.from_format("Apr 2 12:00:00 2020 GMT", "MMM DD HH:mm:ss YYYY z")
53+
54+
4555
@pytest.mark.parametrize(
4656
"text,fmt,expected,now",
4757
[

0 commit comments

Comments
 (0)