serhiy-storchaka · GitHub

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

Read the original on github.com ↗