Skip to content

Commit

Permalink
Parser Token Validation (#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
ALee008 committed Jul 30, 2021
1 parent 255f717 commit fe1afe2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion arrow/parser.py
Expand Up @@ -574,9 +574,12 @@ def _parse_token(
elif token in ["a", "A"]:
if value in (self.locale.meridians["am"], self.locale.meridians["AM"]):
parts["am_pm"] = "am"
if "hour" in parts and not 0 <= parts["hour"] <= 12:
raise ParserMatchError(
f"Hour token value must be between 0 and 12 inclusive for token {token!r}."
)
elif value in (self.locale.meridians["pm"], self.locale.meridians["PM"]):
parts["am_pm"] = "pm"

elif token == "W":
parts["weekdate"] = value

Expand Down
5 changes: 5 additions & 0 deletions tests/test_parser.py
Expand Up @@ -210,6 +210,11 @@ def test_parse_numbers(self):
== self.expected
)

def test_parse_am(self):

with pytest.raises(ParserMatchError):
self.parser.parse("2021-01-30 14:00:00 AM", "YYYY-MM-DD HH:mm:ss A")

def test_parse_year_two_digit(self):

self.expected = datetime(1979, 1, 1, 12, 5, 10)
Expand Down

0 comments on commit fe1afe2

Please sign in to comment.