Skip to content

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

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

imabd645 wants to merge 4 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

@StanFromIreland

Copy link
Copy Markdown
Member

Can you please fix the conflicts?

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 3, 2026
@imabd645

imabd645 commented Oct 3, 2026

Copy link
Copy Markdown
Author

Thanks @StanFromIreland , I've merged main into the branch and resolved the conflict in Modules/_datetimemodule.c. Ready for another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants