Skip to content

Commit 4f84b55

Browse files
committed
Fixes from_format() raising an error with the alternative formatter
1 parent 6c2795e commit 4f84b55

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
7+
- Fixed `from_format()` raising an error with the alternative formatter.
8+
9+
310
## [1.3.2] - 2017-11-16
411

512
### Fixed

pendulum/formatting/alternative_formatter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def parse(self, time, fmt):
330330
331331
:rtype: tuple
332332
"""
333+
fmt = re.escape(fmt)
333334
tokens = self._FORMAT_RE.findall(fmt)
334335
if not tokens:
335336
return time
@@ -397,7 +398,7 @@ def _replace_tokens(self, token):
397398
if token.startswith('[') and token.endswith(']'):
398399
return token[1:-1]
399400
elif token.startswith('\\'):
400-
return token[1:]
401+
return token
401402
elif token not in self._REGEX_TOKENS:
402403
raise ValueError('Unsupported token: {}'.format(token))
403404

tests/pendulum_tests/test_create_from_format.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def test_strptime_is_create_from_format(self):
6262
('1234567890', 'X', '2009-02-13T23:31:30+00:00'),
6363
('1234567890123', 'x', '2009-02-13T23:31:30.123000+00:00'),
6464
('2016-10-06', 'YYYY-MM-DD', '2016-10-06T00:00:00+00:00'),
65+
('2016|10|06', 'YYYY|MM|DD', '2016-10-06T00:00:00+00:00'),
66+
('2016(10|06)', 'YYYY(MM|DD)', '2016-10-06T00:00:00+00:00'),
6567
])
6668
def test_from_format(text, fmt, expected):
6769
with pendulum.test(pendulum.create(2015, 11, 12)):

0 commit comments

Comments
 (0)