Skip to content

Reject a decimal fraction of the hour or minute in parse() - #1105

Open
kevincommits wants to merge 1 commit into
python-pendulum:masterfrom
kevincommits:fix/reject-fractional-minutes
Open

kevincommits wants to merge 1 commit into
python-pendulum:masterfrom
kevincommits:fix/reject-fractional-minutes

Conversation

@kevincommits

Copy link
Copy Markdown

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

parse() reads a decimal fraction written after the minute as a fraction of a second, so it returns a wrong time instead of raising:

>>> pendulum.parse("12:30.5", exact=True)
Time(12, 30, 0, 500000)

Expected: ParserError, the same as "2016-10-06T12:30.5" already raises with the Rust parser and as datetime.time.fromisoformat("12:30.5") raises. In ISO 8601, 12:30,5 means 12:30:30, so 12:30:00.5 is wrong under any reading. With PENDULUM_EXTENSIONS=0 the pure Python ISO 8601 parser has the same problem for full datetimes: "2016-10-06T12,5" gives 12:00:00.5.

The common format parser and the pure Python ISO 8601 parser now raise ParserError when a fractional part follows the hour or minute instead of the seconds. Fractional seconds are unchanged. The Rust parser already rejects these strings, so it needs no change. This rejects the form rather than adding support for decimal hours and minutes, which the TODO in the Rust parser leaves open.

The new test covers both parsers with extended and basic forms, a time-only string, and a datetime in the common format.

What I ran: pytest -q tests with and without PENDULUM_EXTENSIONS=0 (1877 passed; test_instance_with_aware_datetime_any_tzinfo fails, and it also fails on master on my machine), mypy, and prek run --all-files.

What I did not run: the clippy step of the Rust lint hook (clippy is not installed here; no Rust code changed), and the other Python versions and operating systems in the CI matrix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant