classification
Title: [linux] strftime renders %Y with only 3 characters
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: duplicate
Dependencies: Superseder: datetime.strftime("%Y") not consistent for years < 1000
View: 13305
Assigned To: Nosy List: belopolsky, brett.cannon, jaraco, p-ganssle
Priority: normal Keywords:

Created on 2019-12-20 05:32 by jaraco, last changed 2019-12-20 19:34 by p-ganssle. This issue is now closed.

Messages (3)
msg358695 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2019-12-20 05:32
On Python 3.8, there's a difference between how datetime.datetime.strftime renders %Y for years < 1000 between Linux and other platforms.

# Linux
$ docker run -it python python -c 'import datetime; print(datetime.date(900,1,1).strftime("%Y"))'                       
900

# macOS
$ python -c 'import datetime; print(datetime.date(900,1,1).strftime("%Y"))'                                             
0900


According to the docs (https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior), one should expect `'0000'` for year zero and so I'd expect `'0900'` for the year 900, so the macOS behavior looks correct to me.
msg358721 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-12-20 17:37
Due note, though, that there's a difference in the implementation of strftime versus strptime, as the former (at least the last time I looked ages ago) uses the libc version of the function and thus probably doesn't try to smooth out differences like this, while the latter is implemented in Python code in the stdlib itself.
msg358735 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-12-20 19:34
This is a duplicate of issue 13305.

Right now we have some shims around `strftime` to improve consistency in some situations and for other reasons, but mostly we just call the libc version.

There is an open issue from 2008 (#3173) to ship our own implementation of strftime that could smooth out some of these issues and try and make the behavior more consistent (though presumably some people have started to rely on platform-specific behaviors by now, so it may be a decent amount of work to roll it out).

I'm going to close this in favor of 13305, but thanks for reporting it!
History
Date User Action Args
2019-12-20 19:34:12p-gansslesetstatus: open -> closed
superseder: datetime.strftime("%Y") not consistent for years < 1000
messages: + msg358735

type: behavior
resolution: duplicate
stage: resolved
2019-12-20 17:37:54brett.cannonsetnosy: + brett.cannon
messages: + msg358721
2019-12-20 06:21:30xtreaksetnosy: + belopolsky, p-ganssle
2019-12-20 05:32:00jaracocreate