]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
date: fix newly-introduced %%-N bug
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Mar 2022 19:23:01 +0000 (11:23 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Mar 2022 19:23:38 +0000 (11:23 -0800)
* src/date.c (adjust_resolution): Don’t mishandle %%-N.
* tests/misc/date.pl (pct-pct): New test.

src/date.c
tests/misc/date.pl

index 163141adcba21b2c64331b16cd8661a6e6a4f409..9a282e2f563bfa93eecb946414ba443d3aecf5e9 100644 (file)
@@ -310,12 +310,17 @@ adjust_resolution (char const *format)
   char *copy = NULL;
 
   for (char const *f = format; *f; f++)
-    if (f[0] == '%' && f[1] == '-' && f[2] == 'N')
+    if (f[0] == '%')
       {
-        if (!copy)
-          copy = xstrdup (format);
-        copy[f + 1 - format] = '0' + res_width (gettime_res ());
-        f += 2;
+        if (f[1] == '-' && f[2] == 'N')
+          {
+            if (!copy)
+              copy = xstrdup (format);
+            copy[f + 1 - format] = '0' + res_width (gettime_res ());
+            f += 2;
+          }
+        else
+          f += f[1] == '%';
       }
 
   return copy;
index ef7080e33465515c5e7fd022ddc15e735954ca71..f40a377023532915b6a26d4cbe49c4b035f38c70 100755 (executable)
@@ -313,6 +313,9 @@ my @Tests =
      ['mtz4', '-u -d "09:00T" +%T', {OUT => '16:00:00'}],
      ['mtz5', '-u -d "09:00X" +%T', {OUT => '20:00:00'}],
      ['mtz6', '-u -d "09:00Z" +%T', {OUT => '09:00:00'}],
+
+     # test with %%-N
+     ['pct-pct', '+%%-N', {OUT => '%-N'}],
     );
 
 # Repeat the cross-dst test, using Jan 1, 2005 and every interval from 1..364.