]> Savannah Git Hosting - gnulib.git/commitdiff
nstrftime: allow opt-out of AM/PM adjustment
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 14 Feb 2024 06:29:27 +0000 (22:29 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 14 Feb 2024 06:29:58 +0000 (22:29 -0800)
For Emacs I would rather avoid bringing in the Gnulib locking code,
since Emacs has its own idea about locks and its main engine is
single-threaded anyway.
Provide a way to use the nstrftime module while avoiding its
recently-added localename dependency, which entails locking code.
(It’s not clear to me that the locking code is needed for nstrftime,
as NetBSD has strftime_z and Solaris locales could be inspected in
some thread-safe way, e.g., by probing strftime month names.
Anyway, all that’s more hassle than I want to put up with right now
for the trivial matter of AM/PM behavior.)
* lib/strftime.c (REQUIRE_GNUISH_STRFTIME_AM_PM):
New macro, which can be overridden by config.h.
(should_remove_ampm, __strftime_internal):
Use it instead of !USE_C_LOCALE when deciding to
implement Gnuish AM/PM behavior.

ChangeLog
lib/strftime.c

index 6f43de09f7247c709690c3c2d591f16ba8c6bd19..2e3959591d8ae737ca5ab03005b8b906ad242cc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2024-02-13  Paul Eggert  <eggert@cs.ucla.edu>
+
+       nstrftime: allow opt-out of AM/PM adjustment
+       For Emacs I would rather avoid bringing in the Gnulib locking code,
+       since Emacs has its own idea about locks and its main engine is
+       single-threaded anyway.
+       Provide a way to use the nstrftime module while avoiding its
+       recently-added localename dependency, which entails locking code.
+       (It’s not clear to me that the locking code is needed for nstrftime,
+       as NetBSD has strftime_z and Solaris locales could be inspected in
+       some thread-safe way, e.g., by probing strftime month names.
+       Anyway, all that’s more hassle than I want to put up with right now
+       for the trivial matter of AM/PM behavior.)
+       * lib/strftime.c (REQUIRE_GNUISH_STRFTIME_AM_PM):
+       New macro, which can be overridden by config.h.
+       (should_remove_ampm, __strftime_internal):
+       Use it instead of !USE_C_LOCALE when deciding to
+       implement Gnuish AM/PM behavior.
+
 2024-02-13  Bruno Haible  <bruno@clisp.org>
 
        uniwidth/width tests: Update unit test for last commit.
index b6c0b11e00763a9764142115d5ee9fcd8a8413c4..c7256c3d354c6895bf5ee499bc1c4905788a98c7 100644 (file)
 # include "time-internal.h"
 #endif
 
+/* Whether to require GNU behavior for AM and PM indicators, even on
+   other platforms.  This matters only in non-C locales.
+   The default is to require it; you can override this via
+   AC_DEFINE([REQUIRE_GNUISH_STRFTIME_AM_PM], 1) and if you do that
+   you may be able to omit Gnulib's localename module and its dependencies.  */
+#ifndef REQUIRE_GNUISH_STRFTIME_AM_PM
+# define REQUIRE_GNUISH_STRFTIME_AM_PM true
+#endif
+#if USE_C_LOCALE
+# undef REQUIRE_GNUISH_STRFTIME_AM_PM
+# define REQUIRE_GNUISH_STRFTIME_AM_PM false
+#endif
+
 #if USE_C_LOCALE
 # include "c-ctype.h"
 #else
@@ -83,7 +96,7 @@ extern char *tzname[];
 # include <locale.h>
 #endif
 
-#if (defined __NetBSD__ || defined __sun) && !USE_C_LOCALE
+#if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
 # include <locale.h>
 # include "localename.h"
 #endif
@@ -375,7 +388,7 @@ c_locale (void)
 #endif
 
 
-#if (defined __NetBSD__ || defined __sun) && !USE_C_LOCALE
+#if (defined __NetBSD__ || defined __sun) && REQUIRE_GNUISH_STRFTIME_AM_PM
 
 /* Return true if an AM/PM indicator should be removed.  */
 static bool
@@ -1361,7 +1374,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
                           }
                       }
                   }
-#  if !USE_C_LOCALE
+#  if REQUIRE_GNUISH_STRFTIME_AM_PM
                 /* The output of the strftime %p and %r directives contains
                    an AM/PM indicator even for locales where it is not
                    suitable, such as French.  Remove this indicator.  */