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

Inconsistent behaviour in strftime #85868

Closed
valdemarrolfsen mannequin opened this issue Sep 3, 2020 · 3 comments
Closed

Inconsistent behaviour in strftime #85868

valdemarrolfsen mannequin opened this issue Sep 3, 2020 · 3 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@valdemarrolfsen
Copy link
Mannequin

valdemarrolfsen mannequin commented Sep 3, 2020

BPO 41702
Nosy @abalkin, @ned-deily, @MojoVampire, @pganssle, @valdemarrolfsen

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:

assignee = None
closed_at = <Date 2021-12-10.09:51:56.998>
created_at = <Date 2020-09-03.11:45:52.911>
labels = ['3.7', 'type-bug', 'library']
title = 'Inconsistent behaviour in strftime'
updated_at = <Date 2021-12-10.09:51:56.996>
user = 'https://github.com/valdemarrolfsen'

bugs.python.org fields:

activity = <Date 2021-12-10.09:51:56.996>
actor = 'iritkatriel'
assignee = 'none'
closed = True
closed_date = <Date 2021-12-10.09:51:56.998>
closer = 'iritkatriel'
components = ['Library (Lib)']
creation = <Date 2020-09-03.11:45:52.911>
creator = 'valdemarrolfsen'
dependencies = []
files = []
hgrepos = []
issue_num = 41702
keywords = []
message_count = 3.0
messages = ['376296', '376313', '376540']
nosy_count = 5.0
nosy_names = ['belopolsky', 'ned.deily', 'josh.r', 'p-ganssle', 'valdemarrolfsen']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41702'
versions = ['Python 3.7']

@valdemarrolfsen
Copy link
Mannequin Author

valdemarrolfsen mannequin commented Sep 3, 2020

Inconsistency in strftime between python 3.6 and 3.7 when parsing first-century dates.

Python 3.6
>>> datetime.datetime.strptime(d, "%Y-%m-%d").strftime("%Y-%m-%d")
'0020-10-05'

Python 3.7
>>> datetime.datetime.strptime("0020-10-05", "%Y-%m-%d").strftime("%Y-%m-%d")
'20-10-05'

This means that the following would work for 3.6 but raise a ValueError for 3.7:

>> d = "0020-10-05"
>> d = datetime.datetime.strptime(d, "%Y-%m-%d").strftime("%Y-%m-%d")
>> d = datetime.datetime.strptime(d, "%Y-%m-%d").strftime("%Y-%m-%d")

@valdemarrolfsen valdemarrolfsen mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Sep 3, 2020
@MojoVampire
Copy link
Mannequin

MojoVampire mannequin commented Sep 3, 2020

3.8.2 (on Alpine Linux under WSL) produces '0020-10-05', just like your 3.6 example. Not seeing anything obvious in commit history that would break it for 3.7. That said, 3.7 is in security fix only mode at this point (see https://devguide.python.org/#status-of-python-branches ); as this works on the latest release, I'm thinking this won't be fixed for 3.7.

@MojoVampire MojoVampire mannequin changed the title Inconcistent behaviour in strftime Inconsistent behaviour in strftime Sep 3, 2020
@MojoVampire MojoVampire mannequin changed the title Inconcistent behaviour in strftime Inconsistent behaviour in strftime Sep 3, 2020
@ned-deily
Copy link
Member

The behavior you see with a Python 3.7 is not universal. For example, on macOS:

Python 3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.strptime("0020-10-05", "%Y-%m-%d").strftime("%Y-%m-%d")
'0020-10-05'

So there is apparently something different in the environments between the Python 3.6 and 3.7 you are using, rather than an issue in Python itself. Perhaps a comparison of the outputs between:

python3.6 -m test.pythoninfo
python3.7 -m test.pythoninfo

will suggest something. In any case, as Josh notes, Python 3.7 is in the security-fix-only phase of its life cycle so even if there were an issue in Python itself it would likely not meet the criteria to be fixed in 3.7.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants