]> Savannah Git Hosting - gnulib.git/commitdiff
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>
Fri, 31 May 2024 22:05:29 +0000 (00:05 +0200)
* doc/posix-functions/strftime.texi: Mention the %c problem.
* lib/nstrftime.c: Include <locale.h>. 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/nstrftime.c
modules/nstrftime
modules/nstrftime-tests

index b191bca752ecf51e896edd3989be7d292ea01383..8a90f3e2f1d3c6ab2d688bc6de25b31e691cb56d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-05-27  Bruno Haible  <bruno@clisp.org>
+
+       nstrftime: Make %c work on native Windows.
+       * doc/posix-functions/strftime.texi: Mention the %c problem.
+       * lib/nstrftime.c: Include <locale.h>. 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 13605c24c22cc36512037bdc3d170bda7e1cac0a..a4b47dc343b389203582be741784af7488643652 100644 (file)
@@ -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).
index 21596329021d2c3abd6b8ecbe053e508cab67b57..a7b8a411460578b9f84f82aa00ed4d7e4e879967 100644 (file)
@@ -67,6 +67,9 @@ extern char *tzname[];
 #include <stdlib.h>
 #include <string.h>
 
+#include <locale.h>
+#include "hard-locale.h"
+
 #include "attribute.h"
 #include <intprops.h>
 
@@ -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
index fdaf7913d3397c9c3db7792cf38e6896802a9730..35945575b8f9ad33d09dc54ea058919c9112439d 100644 (file)
@@ -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
 
index 52b99aa80236079706864d0fc3864c7dee397428..82ddd9fb34fb8bfa229489dda0e409546c4a4bbb 100644 (file)
@@ -14,3 +14,4 @@ configure.ac:
 Makefile.am:
 TESTS += test-nstrftime
 check_PROGRAMS += test-nstrftime
+test_nstrftime_LDADD = $(LDADD) $(HARD_LOCALE_LIB)