Skip to content

Commit 256e53f

Browse files
authored
Merge pull request #663 from JBKahn/patch-1
0.15.0 regression - Support negative numbers in the timestamp regular expression
2 parents 9b05216 + 1974316 commit 256e53f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

arrow/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DateTimeParser(object):
4545
_TZ_NAME_RE = re.compile(r"\w[\w+\-/]+")
4646
# NOTE: timestamps cannot be parsed from natural language strings (by removing the ^...$) because it will
4747
# break cases like "15 Jul 2000" and a format list (see issue #447)
48-
_TIMESTAMP_RE = re.compile(r"^\d+\.?\d+$")
48+
_TIMESTAMP_RE = re.compile(r"^-?\d+\.?\d+$")
4949
_TIME_RE = re.compile(r"^(\d{2})(?:\:?(\d{2}))?(?:\:?(\d{2}))?(?:([\.\,])(\d+))?$")
5050

5151
_BASE_INPUT_RE_MAP = {

tests/parser_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ def test_parse_timestamp(self):
224224
self.parser.parse("{:f}123456".format(float_timestamp), "X"), self.expected
225225
)
226226

227+
negative_timestamp = -1565358758
228+
self.expected = datetime.fromtimestamp(negative_timestamp, tz=tz_utc)
229+
self.assertEqual(
230+
self.parser.parse("{:d}".format(negative_timestamp), "X"), self.expected
231+
)
232+
227233
# NOTE: timestamps cannot be parsed from natural language strings (by removing the ^...$) because it will
228234
# break cases like "15 Jul 2000" and a format list (see issue #447)
229235
with self.assertRaises(ParserError):

0 commit comments

Comments
 (0)