]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
date: support overriding named formats
authorPádraig Brady <P@draigBrady.com>
Sat, 6 Sep 2025 19:41:29 +0000 (20:41 +0100)
committerPádraig Brady <P@draigBrady.com>
Sun, 7 Sep 2025 12:02:48 +0000 (13:02 +0100)
* src/date.c (main): Allow specifying different named formats,
with the last specified taking precedence.
* NEWS: Mention the bug fix.

NEWS
src/date.c

diff --git a/NEWS b/NEWS
index a1d1318cb20d3c5ef122b2db31c93fe16811d7a1..db9076c3423dc4644f7fcc4c48108f5d86cbf589 100644 (file)
--- 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.
index 42e66e25d34a243c80a708d3774a2d1b049d2e8f..f3a8241cf88f039fcc9272000491337e9eac30bc 100644 (file)
@@ -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