Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.15.0 regression - Support negative numbers in the timestamp regular expression #663

Merged
merged 3 commits into from Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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