Skip to content

gh-56959: Add cross-platform support for %s strftime-format code - #155964

Open
imabd645 wants to merge 3 commits into
python:mainfrom
imabd645:fix-strftime-56959
Open

gh-56959: Add cross-platform support for %s strftime-format code#155964
imabd645 wants to merge 3 commits into
python:mainfrom
imabd645:fix-strftime-56959

Conversation

@imabd645

@imabd645 imabd645 commented Aug 17, 2026

Copy link
Copy Markdown

Adds cross-platform support for the %s format code (UNIX timestamp, representing the number of seconds since the Epoch) in the datetime module's strftime wrapper.

On Unix, %s is natively supported by the underlying C runtime library, while on Windows it is typically not supported and varies unpredictably. This patch normalizes the behavior by intercepting %s internally for datetime instances, guaranteeing cross-platform consistency.

  • Implemented make_sreplacement in Modules/_datetimemodule.c to handle the conversion before passing the format to the native platform strftime() C function.
  • Replicated the logic in the pure-Python fallback (Lib/_pydatetime.py).
  • Added tests for %s covering timezone-aware and naive timestamps, including negative pre-epoch timestamps, to Lib/test/datetimetester.py.
  • Updated the strftime() formatting table and footnotes in Doc/library/datetime.rst.
  • Included a NEWS blurb.

@read-the-docs-community

read-the-docs-community Bot commented Aug 17, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34106113 | 📁 Comparing d6aa03d against main (fa0ec86)

  🔍 Preview build  

2 files changed
± library/datetime.html
± whatsnew/changelog.html

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

Successfully merging this pull request may close these issues.

1 participant