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

Faulty behavior of "dayfirst" or another issue leading to wrong parsing #1334

Open
MathiasWedeken opened this issue Jan 18, 2024 · 2 comments

Comments

@MathiasWedeken
Copy link

Title is unclear, since I don't know WHAT causes the issue. But "dayfirst=True" implies logically that month comes last in the string. But check this:

>>> parse("2020-1-10", dayfirst=True)
datetime.datetime(2020, 10, 1, 0, 0) #correct

>>> parse("2020-1-10", dayfirst=False)
datetime.datetime(2020, 1, 10, 0, 0) #correct

>>> parse("2020-09-30", dayfirst=True)
datetime.datetime(2020, 9, 30, 0, 0) #false, should give an error because month can't be bigger than 12

>>> parse("2020-09-30", dayfirst=False)
datetime.datetime(2020, 9, 30, 0, 0) #correct

parse("2020-30-09", dayfirst=True)
datetime.datetime(2020, 9, 30, 0, 0) #correct 

>>> parse("2020-30-09", dayfirst=False)
dateutil.parser._parser.ParserError: month must be in 1..12: 2020-30-09 #That's the expected output 

So, it looks like "something is wrong" when dayfirst=True.
It could have been the range check that results in a parserError month must be in 1..12: does not happen, but:

>>> parse("2020-09-31", dayfirst=True)
dateutil.parser._parser.ParserError: day is out of range for month: 2020-09-31 #huh? what about dayfirst???  
@loafthecomputerphile
Copy link

Yeah i have the same issue and it seems for some reason that everyone is fine with it.

@Gorillatheif
Copy link

From parser._parse docstring:

::param dayfirst
Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the day (True) or month (False).
If yearfirst is set to True, this distinguishes between YDM and YMD.

So seems like this parameter is not considered when providing a 4 character year, as in your examples.

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

3 participants