From: Bruno Haible Date: Mon, 27 May 2024 21:01:50 +0000 (+0200) Subject: nstrftime, c-nstrftime: Make %c work on native Windows. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=607815bc0487cf813fa4cc353e6888144f34c89f;p=gnulib.git nstrftime, c-nstrftime: Make %c work on native Windows. * doc/posix-functions/strftime.texi: Mention the %c problem. * lib/strftime.c: Include always. 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). --- diff --git a/ChangeLog b/ChangeLog index 186c035d7d..10e464af78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2024-05-27 Bruno Haible + + nstrftime, c-nstrftime: Make %c work on native Windows. + * doc/posix-functions/strftime.texi: Mention the %c problem. + * lib/strftime.c: Include always. 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 0c51c7ecdf..68af3224a4 100644 --- a/doc/posix-functions/strftime.texi +++ b/doc/posix-functions/strftime.texi @@ -21,6 +21,10 @@ or @code{gmtime_r}, since it outputs also the current time zone, on some platforms: glibc 2.30, NetBSD 10.0, Solaris 11.4. @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 %r specifier produces empty output, at least in a French locale, on some platforms: macOS 12.5, FreeBSD 14.0. diff --git a/lib/strftime.c b/lib/strftime.c index 834f3a79f4..069bab7095 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -92,14 +92,13 @@ extern char *tzname[]; #include #include -#if USE_C_LOCALE && HAVE_STRFTIME_L -# include -#endif - +#include #if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM -# include # include "localename.h" #endif +#if !USE_C_LOCALE +# include "hard-locale.h" +#endif #include "attribute.h" #include @@ -1288,6 +1287,12 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_T_FMT)); #elif USE_C_LOCALE && !HAVE_STRFTIME_L subfmt = L_("%a %b %e %H:%M:%S %Y"); +#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 69b9d84605..a9e86fb1f8 100644 --- a/modules/nstrftime +++ b/modules/nstrftime @@ -14,6 +14,7 @@ c99 errno extensions intprops +hard-locale libc-config localename-unsafe-limited stdbool @@ -29,6 +30,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 b5c6ac2fa5..40ea1bd199 100644 --- a/modules/nstrftime-tests +++ b/modules/nstrftime-tests @@ -26,4 +26,4 @@ TESTS_ENVIRONMENT += \ LOCALE_FR='@LOCALE_FR@' \ LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' check_PROGRAMS += test-nstrftime -test_nstrftime_LDADD = $(LDADD) $(SETLOCALE_LIB) +test_nstrftime_LDADD = $(LDADD) $(SETLOCALE_LIB) $(HARD_LOCALE_LIB)