Skip to content

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Status
    Done
    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions