]> Savannah Git Hosting - gnulib.git/commitdiff
nstrftime, c-nstrftime: Make %c work on native Windows.
authorBruno Haible <bruno@clisp.org>
Mon, 27 May 2024 21:01:50 +0000 (23:01 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 27 May 2024 21:01:50 +0000 (23:01 +0200)
* doc/posix-functions/strftime.texi: Mention the %c problem.
* lib/strftime.c: Include <locale.h> 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).

ChangeLog
doc/posix-functions/strftime.texi
lib/strftime.c
modules/nstrftime
modules/nstrftime-tests

index 186c035d7dbe170cf14755119031f83884d8d89a..10e464af786c06c28263ad35051733a651e31319 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-05-27  Bruno Haible  <bruno@clisp.org>
+
+       nstrftime, c-nstrftime: Make %c work on native Windows.
+       * doc/posix-functions/strftime.texi: Mention the %c problem.
+       * lib/strftime.c: Include <locale.h> 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  <bruno@clisp.org>
 
        tests: Fix internationalization problems on native Windows.
index 0c51c7ecdfe610e8b49ca5e800509960d402bd07..68af3224a4878b7da2eee77016ff0763c038708f 100644 (file)
@@ -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.
index 834f3a79f46d68bce57dfb74b6c9bd9a48c2ad21..069bab7095246d8794fbf60f308dd4324334de30 100644 (file)
@@ -92,14 +92,13 @@ extern char *tzname[];
 #include <stdlib.h>
 #include <string.h>
 
-#if USE_C_LOCALE && HAVE_STRFTIME_L
-# include <locale.h>
-#endif
-
+#include <locale.h>
 #if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
-# include <locale.h>
 # include "localename.h"
 #endif
+#if !USE_C_LOCALE
+# include "hard-locale.h"
+#endif
 
 #include "attribute.h"
 #include <intprops.h>
@@ -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
index 69b9d84605a19adff3921e9a81d70c77595dc297..a9e86fb1f8d7eeffe71877b3ac7b8908966412ea 100644 (file)
@@ -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
 
index b5c6ac2fa50a087978510a2effa5c54eb8d7b173..40ea1bd1995d0045dd586f46d6cb83ed91458114 100644 (file)
@@ -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)