From 97de013218d93283db713a7b491d1b4c04e33d6e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 27 May 2024 23:29:36 +0200 Subject: [PATCH] nstrftime: Make %r work on macOS, FreeBSD, native Windows. * doc/posix-functions/strftime.texi: Mention the %r problem. * lib/nstrftime.c (__strftime_internal): On macOS, FreeBSD, and native Windows, for %r, use the English AM/PM format. --- ChangeLog | 7 +++++++ doc/posix-functions/strftime.texi | 3 +++ lib/nstrftime.c | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6b90eb2bd2..9a6f195f6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-05-27 Bruno Haible + + nstrftime: Make %r work on macOS, FreeBSD, native Windows. + * doc/posix-functions/strftime.texi: Mention the %r problem. + * lib/nstrftime.c (__strftime_internal): On macOS, FreeBSD, and native + Windows, for %r, use the English AM/PM format. + 2024-05-27 Bruno Haible nstrftime: Make %h work on native Windows. diff --git a/doc/posix-functions/strftime.texi b/doc/posix-functions/strftime.texi index b0bd2b536e..1455fcdc9c 100644 --- a/doc/posix-functions/strftime.texi +++ b/doc/posix-functions/strftime.texi @@ -23,6 +23,9 @@ mingw, MSVC. The %h specifier produces empty output on some platforms: mingw, MSVC. @item +The %r specifier produces empty 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 ed9118ab1c..bb0ac99cb2 100644 --- a/lib/nstrftime.c +++ b/lib/nstrftime.c @@ -1181,6 +1181,11 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) == L_('\0')) subfmt = L_("%I:%M:%S %p"); goto subformat; +#elif (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || (defined _WIN32 && !defined __CYGWIN__) + /* macOS, FreeBSD, native Windows strftime() may produce empty output + for "%r". */ + subfmt = L_("%I:%M:%S %p"); + goto subformat; #else goto underlying_strftime; #endif -- 2.39.5