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

port default argument from dateutil.parser.parse to dateutil.parser.isoparse #1364

Open
itcarroll opened this issue Apr 26, 2024 · 0 comments

Comments

@itcarroll
Copy link

itcarroll commented Apr 26, 2024

The ability to specify the default is very useful in datetutil.parser.parse. Would you be interested in allowing the same argument for the more strict dateutil.parser.isoparse?

The following is current behavior on the reduced precision ISO 8601 string "2024-04" and its US equivalent "April 2024".

from datetime import datetime
from dateutil.parser import isoparse, parse

isoparse("2024-04")  # datetime.datetime(2024, 4, 1, 0, 0)
parse("April 2024")  # datetime.datetime(2024, 4, 26, 0, 0)
parse("April 2024", default=datetime.max)  # datetime.datetime(2024, 4, 30, 23, 59, 59, 999999)

What I'm needing to do is parse only ISO 8601 strings while having the option to "round up" (in addition to the "round down" approach of the current version). The enhancement would allow something like the following:

isoparse("2024-04", default=datetime.max)  # datetime.datetime(2024, 4, 30, 23, 59, 59, 999999)
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

No branches or pull requests

1 participant