From b3896b082ce6f8aef09a9bbea9c47514f91d0166 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 22 Jul 2026 12:46:29 +0300 Subject: [PATCH 1/2] gh-154460: Do not use wcsftime() on OpenBSD OpenBSD's wcsftime() computes the ISO 8601 week number (%V) incorrectly, while its strftime() is correct. Co-Authored-By: Claude Opus 4.8 --- .../Library/2026-07-22-13-00-00.gh-issue-154460.wCsFtM.rst | 2 ++ Modules/timemodule.c | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-22-13-00-00.gh-issue-154460.wCsFtM.rst diff --git a/Misc/NEWS.d/next/Library/2026-07-22-13-00-00.gh-issue-154460.wCsFtM.rst b/Misc/NEWS.d/next/Library/2026-07-22-13-00-00.gh-issue-154460.wCsFtM.rst new file mode 100644 index 00000000000000..b0a7058f0519ff --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-22-13-00-00.gh-issue-154460.wCsFtM.rst @@ -0,0 +1,2 @@ +Fix :func:`time.strftime` and :meth:`datetime.datetime.strftime` returning a +wrong ISO 8601 week number (``%V``) on OpenBSD. diff --git a/Modules/timemodule.c b/Modules/timemodule.c index d90bf1f2ef90ed..9439ff6d902248 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -763,6 +763,12 @@ Other codes may be available on your platform. See documentation for\n\ the C library strftime function.\n" #ifdef HAVE_STRFTIME +// OpenBSD's wcsftime() computes %V incorrectly: it returns 53 if the ISO 8601 +// week belongs to other year than tm_year. strftime() is correct. +#ifdef __OpenBSD__ +# undef HAVE_WCSFTIME +#endif + #ifdef HAVE_WCSFTIME #define time_char wchar_t #define format_time wcsftime From 1df12b8e4333240328cd624f1133824a81edc8bb Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 22 Jul 2026 13:38:51 +0300 Subject: [PATCH 2/2] Update Modules/timemodule.c Co-authored-by: Stan Ulbrych --- Modules/timemodule.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 9439ff6d902248..70d7e1b3713687 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -763,8 +763,9 @@ Other codes may be available on your platform. See documentation for\n\ the C library strftime function.\n" #ifdef HAVE_STRFTIME -// OpenBSD's wcsftime() computes %V incorrectly: it returns 53 if the ISO 8601 -// week belongs to other year than tm_year. strftime() is correct. +// gh-154460: OpenBSD's wcsftime() computes %V incorrectly: it returns 53 +// whenever the ISO 8601 week belongs to a different year than tm_year. +// strftime() is not affected. #ifdef __OpenBSD__ # undef HAVE_WCSFTIME #endif