Skip to content

time.strftime() returns a wrong ISO 8601 week number (%V) on OpenBSD #154460

Closed

Description

@serhiy-storchaka

Bug report

time.strftime() and datetime.strftime() return a wrong ISO 8601 week number (%V) on OpenBSD:

>>> date(2008, 12, 29).isocalendar()[:2]
(2009, 1)
>>> date(2008, 12, 29).strftime('%G-%V')
'2009-53'

The week number is 53 whenever the ISO 8601 week belongs to other year than the calendar year. %G and %u are correct.

This is a bug in OpenBSD's wcsftime(); its strftime() returns the correct value for the same struct tm. Both contain the same obsolete XPG4-1994 override of the already computed week number, but in strftime.c it is wrapped in #ifdef XPG4_1994_04_09 (never defined), and in wcsftime.c the guard is missing. Reported to bugs@openbsd.org.

We use wcsftime() when HAVE_WCSFTIME is defined, so we can avoid the broken function on OpenBSD. HAVE_WCSFTIME is only used in Modules/timemodule.c, and OpenBSD only supports the C and UTF-8 encodings for LC_CTYPE, so decoding the result of strftime() with the locale encoding is safe there.

This also causes 16 failures in test_strptime.

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    3.16new features, bugs and security fixes
    on Jul 22, 2026
  2. added a commit that references this issue on Jul 22, 2026
  3. added 3 commits that reference this issue on Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixesOS-unsupportedextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions