From 9eddec78661dca44b1e5de31b3e262400020c76f Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Sat, 6 Sep 2025 20:41:29 +0100 Subject: [PATCH] date: support overriding named formats * src/date.c (main): Allow specifying different named formats, with the last specified taking precedence. * NEWS: Mention the bug fix. --- NEWS | 4 ++++ src/date.c | 15 +++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index a1d1318cb2..db9076c342 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,10 @@ GNU coreutils NEWS -*- outline -*- avoiding https://sourceware.org/PR33245 [bug triggered since coreutils-9.0] + 'date' supports specifying multiple named formats with the last taking + precedence. Previously multiple specifications would induce an error. + [bug introduced in coreutils-5.90] + 'install -d' now produces the correct diagnostic upon failure to create a directory. Previously it would have produced a confusing error about changing permissions. diff --git a/src/date.c b/src/date.c index 42e66e25d3..f3a8241cf8 100644 --- a/src/date.c +++ b/src/date.c @@ -487,8 +487,6 @@ main (int argc, char **argv) while ((optc = getopt_long (argc, argv, short_options, long_options, nullptr)) != -1) { - char const *new_format = nullptr; - switch (optc) { case 'd': @@ -516,7 +514,7 @@ main (int argc, char **argv) enum Time_spec i = XARGMATCH ("--rfc-3339", optarg, time_spec_string + 2, time_spec + 2); - new_format = rfc_3339_format[i]; + format = rfc_3339_format[i]; format_in_c_locale = true; break; } @@ -534,7 +532,7 @@ main (int argc, char **argv) (optarg ? XARGMATCH ("--iso-8601", optarg, time_spec_string, time_spec) : TIME_SPEC_DATE); - new_format = iso_8601_format[i]; + format = iso_8601_format[i]; format_in_c_locale = true; break; } @@ -542,7 +540,7 @@ main (int argc, char **argv) reference = optarg; break; case 'R': - new_format = rfc_email_format; + format = rfc_email_format; format_in_c_locale = true; break; case 's': @@ -564,13 +562,6 @@ main (int argc, char **argv) default: usage (EXIT_FAILURE); } - - if (new_format) - { - if (format) - error (EXIT_FAILURE, 0, _("multiple output formats specified")); - format = new_format; - } } int option_specified_date = (!!datestr + !!batch_file + !!reference -- 2.47.3