kennethreitz / maya

Datetimes for Humans™
MIT License
3.41k stars 199 forks source link

day_first parse when year_first format does nothing? #201

Open Owyn opened 5 months ago

Owyn commented 5 months ago

Describe the bug Can't get it to parse as american time when the year is written first

Environment and Version

To Reproduce

>>> maya.parse("2024-01-12 17:13:51", "UTC", True).datetime()
datetime.datetime(2024, 1, 12, 17, 13, 51, tzinfo=<UTC>)
>>> maya.parse("2024-01-12 17:13:51", "UTC", False).datetime()
datetime.datetime(2024, 1, 12, 17, 13, 51, tzinfo=<UTC>)

Expected behavior A way to make it parse 2024-01-12 as 1st of December, not 12th of January

FluffyDietEngine commented 5 months ago

This date format, "YYYY-DD-MM", is not under either ISO 8601 or RFC 3339 date formats. This is the main reason it is being interpreted as "YYYY-MM-DD" instead of expected "YYYY-DD-MM".

Upstream library pendulum have capability of passing format along with the string to parse. This feature can be integrated here to enhance the possibilities.

>>> import pendulum
>>> dt = pendulum.from_format('1975-05-21 22', 'YYYY-MM-DD HH')
>>> print(dt)
'1975-05-21T22:00:00+00:00'

This can be a major enhancement to let the user mention the format to be parsed on.