On 2026-10-21 23:13, Collin Funk wrote:
The first patch is a prerequisite to fixing a GNU coreutils bug
Although I don't know what the bug is, would it be fixed by reverting coreutils
commit b64f9bfe4fd4ce5d276626fd149af2a625b6d434, which I am attaching for
convenience? I had forgotten about posixtime when I made that commit. Reverting
that coreutils commit might be better than complicating Gnulib, as I don't
expect many other uses for posixtime_z.
From b64f9bfe4fd4ce5d276626fd149af2a625b6d434 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Thu, 2 Apr 2026 18:53:34 -0700
Subject: [PATCH] date: simplify -u by not calling putenv
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* src/date.c (TZSET): Remove; no longer needed.
(main): Simplify -u’s implementation by passing "UTC0" to tzalloc,
rather than by setting TZ in the environment and then calling getenv.
The old way of doing things dates back to before we had tzalloc.
* configure.ac (LOCALTIME_CACHE): Remove; no longer needed.
---
configure.ac | 48 ------------------------------------------------
src/date.c | 23 ++++-------------------
2 files changed, 4 insertions(+), 67 deletions(-)
diff --git a/configure.ac b/configure.ac
index 2741dc81b..d7b7915a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -291,54 +291,6 @@ AC_CHECK_FUNCS([sigsuspend],
gl_WINSIZE_IN_PTEM
-AC_MSG_CHECKING([whether localtime caches TZ])
-AC_CACHE_VAL([utils_cv_localtime_cache],
-[if test x$ac_cv_func_tzset = xyes; then
-AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <time.h>
-#if STDC_HEADERS
-# include <stdlib.h>
-#endif
-extern char **environ;
-void unset_TZ (void)
-{
- char **from, **to;
- for (to = from = environ; (*to = *from); from++)
- if (! (to[0][0] == 'T' && to[0][1] == 'Z' && to[0][2] == '='))
- to++;
-}
-int
-main ()
-{
- time_t now = time ((time_t *) 0);
- int hour_GMT0, hour_unset;
- if (putenv ("TZ=GMT0") != 0)
- return 1;
- hour_GMT0 = localtime (&now)->tm_hour;
- unset_TZ ();
- hour_unset = localtime (&now)->tm_hour;
- if (putenv ("TZ=PST8") != 0)
- return 1;
- if (localtime (&now)->tm_hour == hour_GMT0)
- return 1;
- unset_TZ ();
- if (localtime (&now)->tm_hour != hour_unset)
- return 1;
- return 0;
-}]])],
-[utils_cv_localtime_cache=no],
-[utils_cv_localtime_cache=yes],
-[# If we have tzset, assume the worst when cross-compiling.
-utils_cv_localtime_cache=yes])
-else
- # If we lack tzset, report that localtime does not cache TZ,
- # since we can't invalidate the cache if we don't have tzset.
- utils_cv_localtime_cache=no
-fi])dnl
-AC_MSG_RESULT([$utils_cv_localtime_cache])
-if test $utils_cv_localtime_cache = yes; then
- AC_DEFINE([LOCALTIME_CACHE], [1], [FIXME])
-fi
-
# Find the library for dynamic loading of shared libraries.
AC_SEARCH_LIBS([dlopen], [dl])
AS_CASE([$ac_cv_search_dlopen],
diff --git a/src/date.c b/src/date.c
index d37fb5712..14d9204a8 100644
--- a/src/date.c
+++ b/src/date.c
@@ -107,12 +107,6 @@ static struct option const long_options[] =
/* flags for parse_datetime2 */
static unsigned int parse_datetime_flags;
-#if LOCALTIME_CACHE
-# define TZSET tzset ()
-#else
-# define TZSET /* empty */
-#endif
-
#ifdef _DATE_FMT
# define DATE_FMT_LANGINFO() nl_langinfo (_DATE_FMT)
#else
@@ -483,7 +477,7 @@ main (int argc, char **argv)
char *reference = NULL;
bool discarded_datestr = false;
bool discarded_set_datestr = false;
- bool utc = false;
+ char const *tzstring = NULL;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -560,7 +554,7 @@ main (int argc, char **argv)
set_date = true;
break;
case 'u':
- utc = true;
+ tzstring = "UTC0";
break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -569,16 +563,6 @@ main (int argc, char **argv)
}
}
- if (utc)
- {
- /* POSIX says that 'date -u' is equivalent to setting the TZ
- environment variable, so this option should do nothing other
- than setting TZ. */
- if (putenv (bad_cast ("TZ=UTC0")) != 0)
- xalloc_die ();
- TZSET;
- }
-
int option_specified_date = (!!datestr + !!batch_file + !!reference
+ get_resolution);
@@ -649,7 +633,8 @@ main (int argc, char **argv)
char *format_copy = adjust_resolution (format);
char const *format_res = format_copy ? format_copy : format;
- char const *tzstring = getenv ("TZ");
+ if (!tzstring)
+ tzstring = getenv ("TZ");
timezone_t tz = tzalloc (tzstring);
bool ok = true;
--
2.53.0