Skip to content

Commit

Permalink
Merge pull request #663 from JBKahn/patch-1
Browse files Browse the repository at this point in the history
0.15.0 regression - Support negative numbers in the timestamp regular expression
  • Loading branch information
jadchaar committed Sep 10, 2019
2 parents 9b05216 + 1974316 commit 256e53f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arrow/parser.py
Expand Up @@ -45,7 +45,7 @@ class DateTimeParser(object):
_TZ_NAME_RE = re.compile(r"\w[\w+\-/]+")
# NOTE: timestamps cannot be parsed from natural language strings (by removing the ^...$) because it will
# break cases like "15 Jul 2000" and a format list (see issue #447)
_TIMESTAMP_RE = re.compile(r"^\d+\.?\d+$")
_TIMESTAMP_RE = re.compile(r"^-?\d+\.?\d+$")
_TIME_RE = re.compile(r"^(\d{2})(?:\:?(\d{2}))?(?:\:?(\d{2}))?(?:([\.\,])(\d+))?$")

_BASE_INPUT_RE_MAP = {
Expand Down
6 changes: 6 additions & 0 deletions tests/parser_tests.py
Expand Up @@ -224,6 +224,12 @@ def test_parse_timestamp(self):
self.parser.parse("{:f}123456".format(float_timestamp), "X"), self.expected
)

negative_timestamp = -1565358758
self.expected = datetime.fromtimestamp(negative_timestamp, tz=tz_utc)
self.assertEqual(
self.parser.parse("{:d}".format(negative_timestamp), "X"), self.expected
)

# NOTE: timestamps cannot be parsed from natural language strings (by removing the ^...$) because it will
# break cases like "15 Jul 2000" and a format list (see issue #447)
with self.assertRaises(ParserError):
Expand Down

0 comments on commit 256e53f

Please sign in to comment.