Arrow: HH token does not support the number 24, even though the documentation says it should (00 to 24)

Created on 30 Oct 2019  路  3Comments  路  Source: arrow-py/arrow

According to ISO 8601 arrow.get('2019-10-29T24:00:00') should parse to October 30, 2019 (2019-10-30T00:00:00), but instead is throwing an exception ValueError: hour must be in 0..23

It also fails when doing explicit formatting (same exception)
arrow.get('2013-12-31T24:00:00', ['YYYY-MM-DD[T]HH:mm:ss'])

If you look at the docs at https://arrow.readthedocs.io/en/latest/#supported-tokens it says HH token is from 00 to 24

if this is accepted as a bug, it seems a fix for this can be done at arrow/parser.py inside the _build_datetime function ( I can do it, including unit tests)

bug

All 3 comments

Hey @ceorcham, you seem to be correct. On the Wikipedia page it says:

Midnight is a special case and may be referred to as either "00:00" or "24:00". The notation "00:00" is used at the beginning of a calendar day and is the more frequently used. At the end of a day use "24:00". "2007-04-05T24:00" is the same instant as "2007-04-06T00:00".

If you'd like to take this on, go for it!

We should ensure that the new functionality works for both the parser and the formatter.

@jadchaar I just made a PR (#705) with the changes for the parser, now 24:00 will become 00:00 next day. Don't hesitate requesting any changes if needed, I'm happy to help.

I think changes for the formatter are not needed because the 24:00 is just another way to represent next day 00:00, so when formatting HH at midnight will always be 00

Ah yes you are correct! Thanks for the PR by the way--I am reviewing it right now.

Was this page helpful?
0 / 5 - 0 ratings