-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
strptime %d handling of single digit day of month #79084
Comments
strptime correctly parses single digit day-of-month values (at least in the case of "%d %b %Y") which is the behavior I want. However, the documentation seems to say that the field must be two digits with a leading zero if necessary. So I hope that this is the intended behavior rather than just an accidental artifact. If so, then my suggestion is that the documentation be updated to reflect this. |
Hi Mike, Thank you for your issue, but could you add the link to the documentation, just because we have time.strptime and datetime.datetime.strptime. Thank you, |
Sorry for the omission. This refers to datetime.datetime.strptime. The documentation I referenced is: https://docs.python.org/3/library/datetime.html; I did not test 2.7. |
So the documentation reads that way because it was originally written for strftime and has been repurposed to represent both. If the code does the right thing then adding a note that strptime supports single digits accurately would probably be a welcome pull request! |
In addition to %d there are also other items that support single digit though zero padding is mentioned with strptime as below in the context of strftime : >>> import datetime
>>> datetime.datetime.strptime("1/1/2018 1:1:1", "%d/%m/%Y %I:%M:%S")
datetime.datetime(2018, 1, 1, 1, 1, 1)
>>> datetime.datetime.strftime(datetime.datetime(year=2018, month=1, day=1, hour=1, second=1, minute=1), "%d/%m/%Y %I:%M:%S")
'01/01/2018 01:01:01' I couldn't find exact set of words that can be used to denote that zero padding is optional in strptime and it's returned as zero padded in strftime but if we are changing %d then I propose changing other items too with similar wording. Thanks |
Thanks for the quick response. I would be happy to write a pull request for Mike On Sat, Oct 6, 2018 at 7:09 AM Karthikeyan Singaravelan <
|
Thanks for the PR, Mike! This is now merged and backported to Python 3.7, so I believe we can close this issue. |
This is a bit unfortunate for the formats without separators, that could give wrong results silently:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: