From 0dcbff9345238ea2219e60c184866c8fdeea1723 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 27 May 2024 23:01:50 +0200 Subject: [PATCH] nstrftime: Make %c work on native Windows. * doc/posix-functions/strftime.texi: Mention the %c problem. * lib/nstrftime.c: Include . Include hard-locale.h. (__strftime_internal): For %c, use a subformat that contains the weekday name (or abbrev.) and the month name (or abbrev.). * modules/nstrftime (Depends-on): Add hard-locale. (Link): New section. * modules/nstrftime-tests (Makefile.am): Link test-nstrftime with $(HARD_LOCALE_LIB). --- ChangeLog | 12 ++++++++++++ doc/posix-functions/strftime.texi | 4 ++++ lib/nstrftime.c | 9 +++++++++ modules/nstrftime | 4 ++++ modules/nstrftime-tests | 1 + 5 files changed, 30 insertions(+) diff --git a/ChangeLog b/ChangeLog index b191bca752..8a90f3e2f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2024-05-27 Bruno Haible + + nstrftime: Make %c work on native Windows. + * doc/posix-functions/strftime.texi: Mention the %c problem. + * lib/nstrftime.c: Include . Include hard-locale.h. + (__strftime_internal): For %c, use a subformat that contains the weekday + name (or abbrev.) and the month name (or abbrev.). + * modules/nstrftime (Depends-on): Add hard-locale. + (Link): New section. + * modules/nstrftime-tests (Makefile.am): Link test-nstrftime with + $(HARD_LOCALE_LIB). + 2024-05-27 Bruno Haible tests: Fix internationalization problems on native Windows. diff --git a/doc/posix-functions/strftime.texi b/doc/posix-functions/strftime.texi index 13605c24c2..a4b47dc343 100644 --- a/doc/posix-functions/strftime.texi +++ b/doc/posix-functions/strftime.texi @@ -16,6 +16,10 @@ when the environment variable @code{TZ} has been set by Cygwin. Portability problems not fixed by Gnulib: @itemize @item +The %c specifier produces no weekday name and no month name, only a +potentially ambiguous numerical output, on some platforms: +mingw, MSVC. +@item The Windows C runtime library (which is used by MinGW) does not support the %e specifier (and possibly the other more recent SUS specifiers too, i.e., %C, %D, %h, %n, %r, %R, %t, and %T). diff --git a/lib/nstrftime.c b/lib/nstrftime.c index 2159632902..a7b8a41146 100644 --- a/lib/nstrftime.c +++ b/lib/nstrftime.c @@ -67,6 +67,9 @@ extern char *tzname[]; #include #include +#include +#include "hard-locale.h" + #include "attribute.h" #include @@ -835,6 +838,12 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) NLW(ERA_D_T_FMT))) != '\0'))) subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_T_FMT)); +#elif defined _WIN32 && !defined __CYGWIN__ + /* On native Windows, "%c" is "%d/%m/%Y %H:%M:%S" by default. */ + if (hard_locale (LC_TIME)) + subfmt = L_("%a %e %b %Y %H:%M:%S"); + else + subfmt = L_("%a %b %e %H:%M:%S %Y"); #else goto underlying_strftime; #endif diff --git a/modules/nstrftime b/modules/nstrftime index fdaf7913d3..35945575b8 100644 --- a/modules/nstrftime +++ b/modules/nstrftime @@ -13,6 +13,7 @@ c99 errno extensions intprops +hard-locale libc-config stdbool stdckdint @@ -27,6 +28,9 @@ lib_SOURCES += nstrftime.c Include: "strftime.h" +Link: +$(HARD_LOCALE_LIB) + License: LGPL diff --git a/modules/nstrftime-tests b/modules/nstrftime-tests index 52b99aa802..82ddd9fb34 100644 --- a/modules/nstrftime-tests +++ b/modules/nstrftime-tests @@ -14,3 +14,4 @@ configure.ac: Makefile.am: TESTS += test-nstrftime check_PROGRAMS += test-nstrftime +test_nstrftime_LDADD = $(LDADD) $(HARD_LOCALE_LIB) -- 2.39.5