Skip to content

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Feb 18, 2025

Cc: @zeha, @timparenti

This applies further removal of code in get_date(). I'll queue this patch for after the bugfix from #1214 .

This won't be cherry-picked for a stable release, as it's not supposed to fix a reported bug. It just makes get_date() simpler.


Revisions:

v2
  • Restore "" as a synonym for -1. [@zeha]
  • Update manual pages to document YYYY-MM-DD.
$ git range-diff master gh/gd2 gd2 
 1:  e43879f1 =  1:  e43879f1 lib/getdate.y: Ignore time-zone information and use UTC
 2:  f94c0eb0 =  2:  f94c0eb0 lib/getdate.y: Do not parse am/pm time syntax; just 24h
 3:  49cd27a5 =  3:  49cd27a5 lib/getdate.y: Do not parse times; just dates
 4:  acb57848 =  4:  acb57848 lib/getdate.y: Do not parse relative dates, such as 'yesterday'
 5:  3a0a8db8 =  5:  3a0a8db8 lib/getdate.y: Don't parse week days
 6:  1a4cc102 =  6:  1a4cc102 lib/getdate.y: Remove unnecessary variable
 7:  2665e941 =  7:  2665e941 lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
 8:  a6e696c7 =  8:  a6e696c7 lib/getdate.y: Remove unnecessary variable
 9:  3b362acc =  9:  3b362acc lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
10:  ad550562 = 10:  ad550562 lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
11:  885fd28f = 11:  885fd28f lib/getdate.y: Reimplement in pure C
12:  0c1df9f7 = 12:  0c1df9f7 lib/getdate.y: Remove most yacc(1) stuff, which is unused
13:  acf3eb7c = 13:  acf3eb7c *: Get rid of yacc(1)
14:  509b6712 = 14:  509b6712 lib/getdate.c: Fix indentation
15:  a20f12e1 = 15:  a20f12e1 lib/getdate.c: Don't use global variables
16:  4d841240 = 16:  4d841240 lib/: get_date(): Remove unused parameter
17:  1db9755d = 17:  1db9755d lib/strtoday.c: strtoday(): Remove obsolete comment
18:  759abefc = 18:  759abefc lib/strtoday.c: strtoday(): Don't skip spaces between a '-' and a number
19:  69917d00 = 19:  69917d00 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
20:  22fe046e = 20:  22fe046e lib/: Move get_date() to lib/strtoday.c
21:  a3da8739 ! 21:  8ba2e436 lib/strtoday.c: Remove dead code
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/strtoday.c: Remove dead code
    +    lib/strtoday.c: Remove obsolete comment
     
    -    get_date() doesn't treat "" as a date anymore.
    +    get_date() doesn't treat "" as a date anymore, so the comment is
    +    obsolete.  We still need the code, though, as for example usermod(8)
    +    uses an empty string as a synonym for -1.
     
    +    Link: <https://github.com/shadow-maint/shadow/pull/1217#issuecomment-2668174079>
    +    Reported-by: Chris Hofstaedtler <zeha@debian.org>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/strtoday.c ##
    @@ lib/strtoday.c: strtoday(const char *str)
     -   * (useradd sets sp_expire = current date for new lusers)
     -   */
     -  if ((NULL == str) || streq(str, "")) {
    -+  if (NULL == str)
    ++  if (NULL == str || streq(str, ""))
                return -1;
     -  }
      
22:  ce482400 = 22:  003e8fd6 lib/strtoday.c: Use strptime(3) to simplify
23:  33d97af5 ! 23:  34aac64c lib/strtoday.c: Actually return a date from get_date()
    @@ lib/strtoday.c
        long  d;
     -  time_t t;
      
    -   if (NULL == str)
    +   if (NULL == str || streq(str, ""))
                return -1;
     @@ lib/strtoday.c: strtoday(const char *str)
        if (str2sl(&d, str) == 0)
 -:  -------- > 24:  ffd0ea98 man/: Consistently express dates in standard format
 -:  -------- > 25:  6efe4daf man/: Localized dates are not accepted anymore
v2b
  • Reorder commits.
$ git range-diff master gh/gd2 gd2 
 1:  e43879f1 =  1:  e43879f1 lib/getdate.y: Ignore time-zone information and use UTC
 2:  f94c0eb0 =  2:  f94c0eb0 lib/getdate.y: Do not parse am/pm time syntax; just 24h
 3:  49cd27a5 =  3:  49cd27a5 lib/getdate.y: Do not parse times; just dates
 4:  acb57848 =  4:  acb57848 lib/getdate.y: Do not parse relative dates, such as 'yesterday'
 5:  3a0a8db8 =  5:  3a0a8db8 lib/getdate.y: Don't parse week days
 6:  1a4cc102 =  6:  1a4cc102 lib/getdate.y: Remove unnecessary variable
 7:  2665e941 =  7:  2665e941 lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
 8:  a6e696c7 =  8:  a6e696c7 lib/getdate.y: Remove unnecessary variable
 9:  3b362acc =  9:  3b362acc lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
10:  ad550562 = 10:  ad550562 lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
11:  885fd28f = 11:  885fd28f lib/getdate.y: Reimplement in pure C
12:  0c1df9f7 = 12:  0c1df9f7 lib/getdate.y: Remove most yacc(1) stuff, which is unused
13:  acf3eb7c = 13:  acf3eb7c *: Get rid of yacc(1)
14:  509b6712 = 14:  509b6712 lib/getdate.c: Fix indentation
16:  4d841240 ! 15:  5d088c1b lib/: get_date(): Remove unused parameter
    @@ lib/getdate.c: static int parse_date(const char *s);
     -get_date(const char *p, const time_t *now)
     +get_date(const char *s);
      {
    -   long       y, m, d;
        struct tm  tm;
    + 
     
      ## lib/getdate.h ##
     @@
17:  1db9755d = 16:  3291dc71 lib/strtoday.c: strtoday(): Remove obsolete comment
18:  759abefc = 17:  bd918ac8 lib/strtoday.c: strtoday(): Don't skip spaces between a '-' and a number
19:  69917d00 = 18:  072ecfb4 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
21:  8ba2e436 ! 19:  a31a6de7 lib/strtoday.c: Remove obsolete comment
    @@ Commit message
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/strtoday.c ##
    -@@ lib/strtoday.c: strtoday(const char *str)
    +@@ lib/strtoday.c: long strtoday (const char *str)
        long  d;
        time_t t;
      
24:  ffd0ea98 = 20:  e76add92 man/: Consistently express dates in standard format
25:  6efe4daf = 21:  41303f1c man/: Localized dates are not accepted anymore
15:  a20f12e1 ! 22:  5f4bec5c lib/getdate.c: Don't use global variables
    @@ lib/getdate.c
      
      
      time_t
    - get_date(const char *p, const time_t *now)
    + get_date(const char *s);
      {
     +  long       y, m, d;
        struct tm  tm;
    @@ lib/getdate.c
        tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
        tm.tm_isdst = 0;
      
    -@@ lib/getdate.c: get_date(const char *p, const time_t *now)
    +@@ lib/getdate.c: get_date(const char *s);
      
      
      static int
20:  22fe046e = 23:  90895715 lib/: Move get_date() to lib/strtoday.c
22:  003e8fd6 = 24:  35202e36 lib/strtoday.c: Use strptime(3) to simplify
23:  34aac64c = 25:  cc31b8fc lib/strtoday.c: Actually return a date from get_date()
v2c
  • Reorganize commits.

Range diff:

$ git range-diff master gh/gd2 gd2 
 1:  e43879f1 =  1:  e43879f1 lib/getdate.y: Ignore time-zone information and use UTC
 2:  f94c0eb0 =  2:  f94c0eb0 lib/getdate.y: Do not parse am/pm time syntax; just 24h
 3:  49cd27a5 =  3:  49cd27a5 lib/getdate.y: Do not parse times; just dates
 4:  acb57848 =  4:  acb57848 lib/getdate.y: Do not parse relative dates, such as 'yesterday'
 5:  3a0a8db8 =  5:  3a0a8db8 lib/getdate.y: Don't parse week days
 6:  1a4cc102 =  6:  1a4cc102 lib/getdate.y: Remove unnecessary variable
 7:  2665e941 =  7:  2665e941 lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
 8:  a6e696c7 =  8:  a6e696c7 lib/getdate.y: Remove unnecessary variable
 9:  3b362acc =  9:  3b362acc lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
10:  ad550562 = 10:  ad550562 lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
11:  885fd28f = 11:  885fd28f lib/getdate.y: Reimplement in pure C
12:  0c1df9f7 = 12:  0c1df9f7 lib/getdate.y: Remove most yacc(1) stuff, which is unused
13:  acf3eb7c = 13:  acf3eb7c *: Get rid of yacc(1)
14:  509b6712 ! 14:  cf6b984c lib/getdate.c: Fix indentation
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/getdate.c: Fix indentation
    +    lib/: Fix indentation and alignment
     
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
    @@ lib/getdate.c: static long  yyYear;
      }
      
      
    +
    + ## lib/strtoday.c ##
    +@@
    +  *        24-sep-72
    +  *        24sep72
    +  */
    +-long strtoday (const char *str)
    ++long
    ++strtoday(const char *str)
    + {
    +   time_t t;
    +   const char *s = str;
15:  5d088c1b ! 15:  0d094adf lib/: get_date(): Remove unused parameter
    @@ lib/getdate.h
      #endif
     
      ## lib/strtoday.c ##
    -@@ lib/strtoday.c: long strtoday (const char *str)
    +@@ lib/strtoday.c: strtoday(const char *str)
                return retdate;
        }
      
24:  35202e36 ! 16:  de40ada5 lib/strtoday.c: Use strptime(3) to simplify
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/strtoday.c: Use strptime(3) to simplify
    +    lib/getdate.c: Use strptime(3) to simplify
     
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
    - ## lib/strtoday.c ##
    + ## lib/getdate.c ##
     @@
      
      #include <config.h>
    @@ lib/strtoday.c
      #include <time.h>
      
     -#include "atoi/a2i/a2s.h"
    - #include "atoi/str2i/str2s.h"
    - #include "defines.h"
    - #include "prototypes.h"
    + #include "getdate.h"
     -#include "string/strchr/strchrcnt.h"
      #include "string/strcmp/streq.h"
     -#include "string/strcmp/strprefix.h"
    @@ lib/strtoday.c
     -
     -
     -#define TM_YEAR_ORIGIN 1900
    - 
    - 
    - static time_t get_date(const char *s);
    +-
    +-
    +-static long  yyDay;
    +-static long  yyMonth;
    +-static long  yyYear;
    +-
    +-
     -static int parse_date(const char *s);
      
      
    - long
    -@@ lib/strtoday.c: strtoday(const char *str)
    - static time_t
    - get_date(const char *s)
    + time_t
    +-get_date(const char *s);
    ++get_date(const char *s)
      {
    --  long       y, m, d;
     -  struct tm  tm;
     +  struct tm   tm;
     +  const char  *p;
      
    --  if (parse_date(p, &y, &m, &d) == -1)
    +-  if (parse_date(p) == -1)
     +  bzero(&tm, sizeof(tm));
     +
     +  p = strptime("UTC", "%Z", &tm);
     +  if (p == NULL || !streq(p, ""))
                return -1;
      
    --  tm.tm_year = y - TM_YEAR_ORIGIN;
    --  tm.tm_mon = m - 1;
    --  tm.tm_mday = d;
    +-  tm.tm_year = yyYear - TM_YEAR_ORIGIN;
    +-  tm.tm_mon = yyMonth - 1;
    +-  tm.tm_mday = yyDay;
     -  tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
     -  tm.tm_isdst = 0;
     +  p = strptime(s, "%F", &tm);
    @@ lib/strtoday.c: strtoday(const char *str)
     -
     -
     -static int
    --parse_date(const char *s, long *y, long *m, long *d)
    +-parse_date(const char *s)
     -{
     -  long  n;
     -
    @@ lib/strtoday.c: strtoday(const char *str)
     -          return -1;
     -  }
     -
    --  if (a2sl(d, s, &s, 10, LONG_MIN, LONG_MAX) == -1 && errno != ENOTSUP)
    +-  if (a2sl(&yyYear, s, &s, 10, LONG_MIN, LONG_MAX) == -1 && errno != ENOTSUP)
     -          return -1;
     -
     -  if (!strprefix(s++, "-"))
     -          return -1;
     -
    --  if (a2sl(m, s, &s, 10, LONG_MIN, LONG_MAX) == -1 && errno != ENOTSUP)
    +-  if (a2sl(&yyMonth, s, &s, 10, LONG_MIN, LONG_MAX) == -1 && errno != ENOTSUP)
     -          return -1;
     -
     -  if (!strprefix(s++, "-"))
     -          return -1;
     -
    --  if (a2sl(d, s, NULL, 10, LONG_MIN, LONG_MAX) == -1)
    +-  if (a2sl(&yyDay, s, NULL, 10, LONG_MIN, LONG_MAX) == -1)
     -          return -1;
     -
     -  return 0;
20:  e76add92 = 17:  c341ef3d man/: Consistently express dates in standard format
21:  41303f1c = 18:  48d8681a man/: Localized dates are not accepted anymore
16:  3291dc71 ! 19:  1550750d lib/strtoday.c: strtoday(): Remove obsolete comment
    @@ lib/strtoday.c
     - *        24-sep-72
     - *        24sep72
     - */
    - long strtoday (const char *str)
    + long
    + strtoday(const char *str)
      {
    -   time_t t;
17:  bd918ac8 ! 20:  211cf239 lib/strtoday.c: strtoday(): Don't skip spaces between a '-' and a number
    @@ Commit message
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/strtoday.c ##
    -@@ lib/strtoday.c: long strtoday (const char *str)
    +@@ lib/strtoday.c: strtoday(const char *str)
        if ('-' == *s) {
                s++;
        }
18:  072ecfb4 ! 21:  cb8ca731 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
    @@ lib/strtoday.c
      #include "string/strcmp/streq.h"
      #include "string/strspn/stpspn.h"
      
    - 
    - long strtoday (const char *str)
    +@@
    + long
    + strtoday(const char *str)
      {
     +  long  d;
        time_t t;
    @@ lib/strtoday.c
      
        /*
         * get_date() interprets an empty string as the current date,
    -@@ lib/strtoday.c: long strtoday (const char *str)
    +@@ lib/strtoday.c: strtoday(const char *str)
        /* If a numerical value is provided, this is already a number of
         * days since EPOCH.
         */
19:  a31a6de7 ! 22:  e3e8506b lib/strtoday.c: Remove obsolete comment
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/strtoday.c: Remove obsolete comment
    +    lib/strtoday.c: strtoday(): Remove obsolete comment
     
         get_date() doesn't treat "" as a date anymore, so the comment is
         obsolete.  We still need the code, though, as for example usermod(8)
    @@ Commit message
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/strtoday.c ##
    -@@ lib/strtoday.c: long strtoday (const char *str)
    +@@ lib/strtoday.c: strtoday(const char *str)
        long  d;
        time_t t;
      
22:  5f4bec5c <  -:  -------- lib/getdate.c: Don't use global variables
23:  90895715 ! 23:  29ac7e74 lib/: Move get_date() to lib/strtoday.c
    @@ lib/getdate.c (deleted)
     -
     -#include <config.h>
     -
    --#include <errno.h>
    --#include <limits.h>
     -#include <stddef.h>
    --#include <string.h>
    +-#include <strings.h>
     -#include <time.h>
     -
    --#include "atoi/a2i/a2s.h"
     -#include "getdate.h"
    --#include "string/strchr/strchrcnt.h"
     -#include "string/strcmp/streq.h"
    --#include "string/strcmp/strprefix.h"
    --#include "string/strcmp/strsuffix.h"
    --#include "string/strspn/stpspn.h"
    --
    --
    --#define TM_YEAR_ORIGIN 1900
    --
    --
    --static int parse_date(const char *s);
     -
     -
     -time_t
    --get_date(const char *s);
    +-get_date(const char *s)
     -{
    --  long       y, m, d;
    --  struct tm  tm;
    +-  struct tm   tm;
    +-  const char  *p;
     -
    --  if (parse_date(p, &y, &m, &d) == -1)
    +-  bzero(&tm, sizeof(tm));
    +-
    +-  p = strptime("UTC", "%Z", &tm);
    +-  if (p == NULL || !streq(p, ""))
     -          return -1;
     -
    --  tm.tm_year = y - TM_YEAR_ORIGIN;
    --  tm.tm_mon = m - 1;
    --  tm.tm_mday = d;
    --  tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
    --  tm.tm_isdst = 0;
    +-  p = strptime(s, "%F", &tm);
    +-  if (p == NULL || !streq(p, ""))
    +-          return -1;
     -
     -  return timegm(&tm);
    --}
    --
    --
    --static int
    --parse_date(const char *s, long *y, long *m, long *d)
    --{
    --  long  n;
    --
    --  if (!streq(stpspn(s, "0123456789-"), "")
    --   || strchrcnt(s, '-') != 2
    --   || strprefix(s, "-")
    --   || strsuffix(s, "-")
    --   || strstr(s, "--"))
    --  {
    --          return -1;
    --  }
    --
    --  if (a2sl(d, s, &s, 10, LONG_MIN, LONG_MAX) == -1 && errno != ENOTSUP)
    --          return -1;
    --
    --  if (!strprefix(s++, "-"))
    --          return -1;
    --
    --  if (a2sl(m, s, &s, 10, LONG_MIN, LONG_MAX) == -1 && errno != ENOTSUP)
    --          return -1;
    --
    --  if (!strprefix(s++, "-"))
    --          return -1;
    --
    --  if (a2sl(d, s, NULL, 10, LONG_MIN, LONG_MAX) == -1)
    --          return -1;
    --
    --  return 0;
     -}
     
      ## lib/getdate.h (deleted) ##
    @@ lib/strtoday.c
      #include <config.h>
      
     -#include <ctype.h>
    -+#include <errno.h>
    -+#include <limits.h>
     +#include <stddef.h>
    -+#include <string.h>
    ++#include <strings.h>
     +#include <time.h>
      
    -+#include "atoi/a2i/a2s.h"
      #include "atoi/str2i/str2s.h"
     -#include "getdate.h"
     +#include "defines.h"
      #include "prototypes.h"
    -+#include "string/strchr/strchrcnt.h"
      #include "string/strcmp/streq.h"
    -+#include "string/strcmp/strprefix.h"
    -+#include "string/strcmp/strsuffix.h"
    - #include "string/strspn/stpspn.h"
    - 
    - 
    --long strtoday (const char *str)
    -+#define TM_YEAR_ORIGIN 1900
    +-#include "string/strspn/stpspn.h"
     +
     +
     +static time_t get_date(const char *s);
    -+static int parse_date(const char *s);
    -+
    -+
    -+long
    -+strtoday(const char *str)
    - {
    -   long  d;
    -   time_t t;
    -@@ lib/strtoday.c: long strtoday (const char *str)
    + 
    + 
    + long
    +@@ lib/strtoday.c: strtoday(const char *str)
        }
        return t / DAY;
      }
    @@ lib/strtoday.c: long strtoday (const char *str)
     +static time_t
     +get_date(const char *s)
     +{
    -+  long       y, m, d;
    -+  struct tm  tm;
    ++  struct tm   tm;
    ++  const char  *p;
     +
    -+  if (parse_date(p, &y, &m, &d) == -1)
    ++  bzero(&tm, sizeof(tm));
    ++
    ++  p = strptime("UTC", "%Z", &tm);
    ++  if (p == NULL || !streq(p, ""))
     +          return -1;
     +
    -+  tm.tm_year = y - TM_YEAR_ORIGIN;
    -+  tm.tm_mon = m - 1;
    -+  tm.tm_mday = d;
    -+  tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
    -+  tm.tm_isdst = 0;
    ++  p = strptime(s, "%F", &tm);
    ++  if (p == NULL || !streq(p, ""))
    ++          return -1;
     +
     +  return timegm(&tm);
     +}
    -+
    -+
    -+static int
    -+parse_date(const char *s, long *y, long *m, long *d)
    -+{
    -+  long  n;
    -+
    -+  if (!streq(stpspn(s, "0123456789-"), "")
    -+   || strchrcnt(s, '-') != 2
    -+   || strprefix(s, "-")
    -+   || strsuffix(s, "-")
    -+   || strstr(s, "--"))
    -+  {
    -+          return -1;
    -+  }
    -+
    -+  if (a2sl(d, s, &s, 10, LONG_MIN, LONG_MAX) == -1 && errno != ENOTSUP)
    -+          return -1;
    -+
    -+  if (!strprefix(s++, "-"))
    -+          return -1;
    -+
    -+  if (a2sl(m, s, &s, 10, LONG_MIN, LONG_MAX) == -1 && errno != ENOTSUP)
    -+          return -1;
    -+
    -+  if (!strprefix(s++, "-"))
    -+          return -1;
    -+
    -+  if (a2sl(d, s, NULL, 10, LONG_MIN, LONG_MAX) == -1)
    -+          return -1;
    -+
    -+  return 0;
    -+}
25:  cc31b8fc = 24:  e6202e4b lib/strtoday.c: Actually return a date from get_date()

Interdiff:

$ git diff gh/gd2..gd2
$
v2d
  • Reorganize commits.

Range diff:

$ git range-diff master gh/gd2 gd2 
 1:  e43879f1 =  1:  e43879f1 lib/getdate.y: Ignore time-zone information and use UTC
 2:  f94c0eb0 =  2:  f94c0eb0 lib/getdate.y: Do not parse am/pm time syntax; just 24h
 3:  49cd27a5 =  3:  49cd27a5 lib/getdate.y: Do not parse times; just dates
 4:  acb57848 =  4:  acb57848 lib/getdate.y: Do not parse relative dates, such as 'yesterday'
 5:  3a0a8db8 =  5:  3a0a8db8 lib/getdate.y: Don't parse week days
 6:  1a4cc102 =  6:  1a4cc102 lib/getdate.y: Remove unnecessary variable
 7:  2665e941 =  7:  2665e941 lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
 8:  a6e696c7 =  8:  a6e696c7 lib/getdate.y: Remove unnecessary variable
 9:  3b362acc =  9:  3b362acc lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
10:  ad550562 = 10:  ad550562 lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
11:  885fd28f = 11:  885fd28f lib/getdate.y: Reimplement in pure C
12:  0c1df9f7 = 12:  0c1df9f7 lib/getdate.y: Remove most yacc(1) stuff, which is unused
13:  acf3eb7c = 13:  acf3eb7c *: Get rid of yacc(1)
14:  cf6b984c = 14:  cf6b984c lib/: Fix indentation and alignment
15:  0d094adf ! 15:  404e61fa lib/: get_date(): Remove unused parameter
    @@ lib/getdate.c: static int parse_date(const char *s);
     
      ## lib/getdate.h ##
     @@
    --/*
    -- * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
    -- * SPDX-FileCopyrightText: 1997 - 2000, Marek Micha<C5><82>kiewicz
    -- * SPDX-FileCopyrightText: 2005       , Tomasz K<C5><82>oczko
    -- *
    -- * SPDX-License-Identifier: BSD-3-Clause
    -- */
    -+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
    -+// SPDX-License-Identifier: BSD-3-Clause
    -+
    - 
    - #ifndef _GETDATE_H_
    - #define _GETDATE_H_
    - 
    --#include <config.h>
    --#include "defines.h"
    + #include <config.h>
    + #include "defines.h"
      
     -time_t get_date (const char *p, /*@null@*/const time_t *now);
    -+#include <config.h>
    -+
    -+#include <time.h>
    -+
    -+
     +time_t get_date(const char *s);
    -+
    -+
      #endif
     
      ## lib/strtoday.c ##
16:  de40ada5 = 16:  5cc78df2 lib/getdate.c: Use strptime(3) to simplify
17:  c341ef3d = 17:  9c778dec man/: Consistently express dates in standard format
18:  48d8681a = 18:  ac519f4a man/: Localized dates are not accepted anymore
19:  1550750d = 19:  e476fe9f lib/strtoday.c: strtoday(): Remove obsolete comment
20:  211cf239 <  -:  -------- lib/strtoday.c: strtoday(): Don't skip spaces between a '-' and a number
21:  cb8ca731 ! 20:  8c2ab210 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
    @@ lib/strtoday.c: strtoday(const char *str)
     -  if ('-' == *s) {
     -          s++;
     -  }
    +-  s = stpspn(s, " ");
     -  if (strisdigit(s)) {
     -          long retdate;
     -
22:  e3e8506b = 21:  b5c5e921 lib/strtoday.c: strtoday(): Remove obsolete comment
23:  29ac7e74 ! 22:  dadce4de lib/: Move get_date() to lib/strtoday.c
    @@ lib/getdate.c (deleted)
     
      ## lib/getdate.h (deleted) ##
     @@
    --// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
    --// SPDX-License-Identifier: BSD-3-Clause
    --
    +-/*
    +- * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
    +- * SPDX-FileCopyrightText: 1997 - 2000, Marek Micha<C5><82>kiewicz
    +- * SPDX-FileCopyrightText: 2005       , Tomasz K<C5><82>oczko
    +- *
    +- * SPDX-License-Identifier: BSD-3-Clause
    +- */
     -
     -#ifndef _GETDATE_H_
     -#define _GETDATE_H_
     -
    --
     -#include <config.h>
    --
    --#include <time.h>
    --
    +-#include "defines.h"
     -
     -time_t get_date(const char *s);
    --
    --
     -#endif
     
      ## lib/strtoday.c ##
24:  e6202e4b = 23:  26a9d393 lib/strtoday.c: Actually return a date from get_date()

Interdiff:

$ git diff gh/gd2..gd2
$
v2e
  • Rebase
$ git range-diff gh/gd..gh/gd2 gd..gd2
 1:  f94c0eb0 !  1:  05681df0 lib/getdate.y: Do not parse am/pm time syntax; just 24h
    @@ lib/getdate.y: item      : time {
     -      yyMeridian = $2;
     -  }
     -  | tUNUMBER ':' tUNUMBER o_merid {
    -+time      : tUNUMBER ':' tUNUMBER tSNUMBER {
    ++time      : tUNUMBER ':' tUNUMBER {
            yyHour = $1;
            yyMinutes = $3;
     -      yySeconds = 0;
     -      yyMeridian = $4;
     -  }
    --  | tUNUMBER ':' tUNUMBER tSNUMBER {
    +-  | tUNUMBER ':' tUNUMBER {
     -      yyHour = $1;
     -      yyMinutes = $3;
     -      yyMeridian = MER24;
    @@ lib/getdate.y: item      : time {
     -      yySeconds = $5;
     -      yyMeridian = $6;
        }
    -   | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
    +   | tUNUMBER ':' tUNUMBER ':' tUNUMBER {
            yyHour = $1;
            yyMinutes = $3;
            yySeconds = $5;
 2:  49cd27a5 !  2:  86fd34b4 lib/getdate.y: Do not parse times; just dates
    @@ lib/getdate.y: item      : time {
        | number
        ;
      
    --time      : tUNUMBER ':' tUNUMBER tSNUMBER {
    +-time      : tUNUMBER ':' tUNUMBER {
     -      yyHour = $1;
     -      yyMinutes = $3;
     -  }
    --  | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
    +-  | tUNUMBER ':' tUNUMBER ':' tUNUMBER {
     -      yyHour = $1;
     -      yyMinutes = $3;
     -      yySeconds = $5;
 3:  acb57848 =  3:  5c3762f0 lib/getdate.y: Do not parse relative dates, such as 'yesterday'
 4:  3a0a8db8 =  4:  182abd05 lib/getdate.y: Don't parse week days
 5:  1a4cc102 =  5:  00911f54 lib/getdate.y: Remove unnecessary variable
 6:  2665e941 =  6:  5e8326b3 lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
 7:  a6e696c7 =  7:  9c146221 lib/getdate.y: Remove unnecessary variable
 8:  3b362acc =  8:  85106b56 lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
 9:  ad550562 =  9:  c21f579c lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
10:  885fd28f = 10:  f6d996c6 lib/getdate.y: Reimplement in pure C
11:  0c1df9f7 = 11:  eb6e3325 lib/getdate.y: Remove most yacc(1) stuff, which is unused
12:  acf3eb7c = 12:  8e172aa6 *: Get rid of yacc(1)
13:  cf6b984c = 13:  bb3be076 lib/: Fix indentation and alignment
14:  404e61fa = 14:  6adc91d1 lib/: get_date(): Remove unused parameter
15:  5cc78df2 = 15:  73021690 lib/getdate.c: Use strptime(3) to simplify
16:  9c778dec = 16:  c0f35bb4 man/: Consistently express dates in standard format
17:  ac519f4a = 17:  148ac24a man/: Localized dates are not accepted anymore
18:  e476fe9f = 18:  f5badcaa lib/strtoday.c: strtoday(): Remove obsolete comment
19:  8c2ab210 = 19:  6a0e93d4 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
20:  b5c5e921 = 20:  f8364044 lib/strtoday.c: strtoday(): Remove obsolete comment
21:  dadce4de = 21:  c979df23 lib/: Move get_date() to lib/strtoday.c
22:  26a9d393 = 22:  f93c551c lib/strtoday.c: Actually return a date from get_date()
v2f
  • Rebase
$ git range-diff gd..gh/gd2 shadow/master..gd2 
 1:  05681df0 =  1:  f20dd8ef lib/getdate.y: Do not parse am/pm time syntax; just 24h
 2:  86fd34b4 =  2:  91e1b5ff lib/getdate.y: Do not parse times; just dates
 3:  5c3762f0 =  3:  3458b404 lib/getdate.y: Do not parse relative dates, such as 'yesterday'
 4:  182abd05 =  4:  8371361e lib/getdate.y: Don't parse week days
 5:  00911f54 =  5:  106ba394 lib/getdate.y: Remove unnecessary variable
 6:  5e8326b3 =  6:  8404b99b lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
 7:  9c146221 =  7:  3fabe30c lib/getdate.y: Remove unnecessary variable
 8:  85106b56 =  8:  da970a02 lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
 9:  c21f579c =  9:  a3221376 lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
10:  f6d996c6 = 10:  46dcf906 lib/getdate.y: Reimplement in pure C
11:  eb6e3325 = 11:  0166a1ac lib/getdate.y: Remove most yacc(1) stuff, which is unused
12:  8e172aa6 = 12:  f9162e7c *: Get rid of yacc(1)
13:  bb3be076 = 13:  e80604f0 lib/: Fix indentation and alignment
14:  6adc91d1 = 14:  25e8c86c lib/: get_date(): Remove unused parameter
15:  73021690 = 15:  a3a4beb2 lib/getdate.c: Use strptime(3) to simplify
16:  c0f35bb4 = 16:  c40c9bb4 man/: Consistently express dates in standard format
17:  148ac24a = 17:  6a4bba0d man/: Localized dates are not accepted anymore
18:  f5badcaa = 18:  2dd1de97 lib/strtoday.c: strtoday(): Remove obsolete comment
19:  6a0e93d4 = 19:  a3cc8f8d lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
20:  f8364044 = 20:  08fc577f lib/strtoday.c: strtoday(): Remove obsolete comment
21:  c979df23 = 21:  fbd1489b lib/: Move get_date() to lib/strtoday.c
22:  f93c551c = 22:  9991dbe0 lib/strtoday.c: Actually return a date from get_date()
v2g
  • Rebase
$ git range-diff master..gh/gd2 shadow/master..gd2 
 1:  f20dd8ef =  1:  95a5865a lib/getdate.y: Do not parse am/pm time syntax; just 24h
 2:  91e1b5ff =  2:  2b378f1d lib/getdate.y: Do not parse times; just dates
 3:  3458b404 =  3:  46d40b0d lib/getdate.y: Do not parse relative dates, such as 'yesterday'
 4:  8371361e =  4:  65c6450e lib/getdate.y: Don't parse week days
 5:  106ba394 =  5:  50519306 lib/getdate.y: Remove unnecessary variable
 6:  8404b99b =  6:  299de7a9 lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
 7:  3fabe30c =  7:  248b66e2 lib/getdate.y: Remove unnecessary variable
 8:  da970a02 =  8:  974da794 lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
 9:  a3221376 =  9:  0322b000 lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
10:  46dcf906 = 10:  9f53f6a6 lib/getdate.y: Reimplement in pure C
11:  0166a1ac = 11:  a397ddc5 lib/getdate.y: Remove most yacc(1) stuff, which is unused
12:  f9162e7c = 12:  da33535f *: Get rid of yacc(1)
13:  e80604f0 = 13:  7e838d17 lib/: Fix indentation and alignment
14:  25e8c86c = 14:  4b87806b lib/: get_date(): Remove unused parameter
15:  a3a4beb2 = 15:  3c614d0c lib/getdate.c: Use strptime(3) to simplify
16:  c40c9bb4 = 16:  a109c101 man/: Consistently express dates in standard format
17:  6a4bba0d = 17:  d165f030 man/: Localized dates are not accepted anymore
18:  2dd1de97 = 18:  2303fac0 lib/strtoday.c: strtoday(): Remove obsolete comment
19:  a3cc8f8d = 19:  b46caafe lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
20:  08fc577f = 20:  01b1b1d7 lib/strtoday.c: strtoday(): Remove obsolete comment
21:  fbd1489b = 21:  f092db62 lib/: Move get_date() to lib/strtoday.c
22:  9991dbe0 = 22:  cb462eb7 lib/strtoday.c: Actually return a date from get_date()
v2h
  • Rebase
$ git range-diff master..gh/gd2 shadow/master..gd2 
 1:  95a5865a =  1:  0b830153 lib/getdate.y: Do not parse am/pm time syntax; just 24h
 2:  2b378f1d =  2:  ce35738c lib/getdate.y: Do not parse times; just dates
 3:  46d40b0d =  3:  64d5d8de lib/getdate.y: Do not parse relative dates, such as 'yesterday'
 4:  65c6450e =  4:  0851afca lib/getdate.y: Don't parse week days
 5:  50519306 =  5:  8c581d5e lib/getdate.y: Remove unnecessary variable
 6:  299de7a9 =  6:  4c923f93 lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
 7:  248b66e2 =  7:  e385099d lib/getdate.y: Remove unnecessary variable
 8:  974da794 =  8:  8928c17e lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
 9:  0322b000 =  9:  a842f13b lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
10:  9f53f6a6 = 10:  2584f687 lib/getdate.y: Reimplement in pure C
11:  a397ddc5 = 11:  233bb8d3 lib/getdate.y: Remove most yacc(1) stuff, which is unused
12:  da33535f = 12:  90ed4c81 *: Get rid of yacc(1)
13:  7e838d17 = 13:  218fdd58 lib/: Fix indentation and alignment
14:  4b87806b = 14:  c13c2ae4 lib/: get_date(): Remove unused parameter
15:  3c614d0c = 15:  d570ef52 lib/getdate.c: Use strptime(3) to simplify
16:  a109c101 = 16:  51e704a0 man/: Consistently express dates in standard format
17:  d165f030 = 17:  07e2690b man/: Localized dates are not accepted anymore
18:  2303fac0 = 18:  3ad0f396 lib/strtoday.c: strtoday(): Remove obsolete comment
19:  b46caafe = 19:  4493cd24 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
20:  01b1b1d7 = 20:  e849314d lib/strtoday.c: strtoday(): Remove obsolete comment
21:  f092db62 = 21:  55eab710 lib/: Move get_date() to lib/strtoday.c
22:  cb462eb7 = 22:  e2475695 lib/strtoday.c: Actually return a date from get_date()
v3
$ git range-diff db/master gh/gd2 gd2 
 1:  0b830153 <  -:  -------- lib/getdate.y: Do not parse am/pm time syntax; just 24h
 2:  ce35738c !  1:  13de308c lib/getdate.y: Do not parse times; just dates
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/getdate.y: Do not parse times; just dates
    +    lib/getdate.y: Don't parse times; just dates
     
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/getdate.y ##
    +@@ lib/getdate.y: typedef struct _TABLE {
    + } TABLE;
    + 
    + 
    +-/*
    +-**  Meridian:  am, pm, or 24-hour style.
    +-*/
    +-typedef enum _MERIDIAN {
    +-    MERam, MERpm, MER24
    +-} MERIDIAN;
    +-
    +-
    + /*
    + **  Global variables.  We could get rid of most of these by using a good
    + **  union as the yacc stack.  (This routine was originally written before
     @@ lib/getdate.y: static int       yyDayNumber;
      static int        yyHaveDate;
      static int        yyHaveDay;
    @@ lib/getdate.y: static int        yyDayNumber;
      static int        yyMonth;
     -static int        yySeconds;
      static int        yyYear;
    +-static MERIDIAN   yyMeridian;
      static int        yyRelDay;
     -static int        yyRelHour;
     -static int        yyRelMinutes;
    @@ lib/getdate.y: static int        yyDayNumber;
      static int        yyRelYear;
      
      %}
    -@@ lib/getdate.y: static int       yyRelYear;
    + 
    + %union {
          int                   Number;
    +-    enum _MERIDIAN        Meridian;
      }
      
     -%token    tAGO tDAY tDAY_UNIT tHOUR_UNIT tID
    --%token    tMINUTE_UNIT tMONTH tMONTH_UNIT
    +-%token    tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
     -%token    tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT
     +%token    tAGO tDAY tDAY_UNIT tID
     +%token    tMONTH tMONTH_UNIT
    @@ lib/getdate.y: static int        yyRelYear;
     +%type     <Number>        tDAY tDAY_UNIT
      %type     <Number>        tMONTH tMONTH_UNIT
     -%type     <Number>        tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT
    +-%type     <Meridian>      tMERIDIAN o_merid
     +%type     <Number>        tSNUMBER tUNUMBER tYEAR_UNIT
      
      %%
    @@ lib/getdate.y: item      : time {
        | number
        ;
      
    --time      : tUNUMBER ':' tUNUMBER {
    +-time      : tUNUMBER tMERIDIAN {
    +-      yyHour = $1;
    +-      yyMinutes = 0;
    +-      yySeconds = 0;
    +-      yyMeridian = $2;
    +-  }
    +-  | tUNUMBER ':' tUNUMBER o_merid {
     -      yyHour = $1;
     -      yyMinutes = $3;
    +-      yySeconds = 0;
    +-      yyMeridian = $4;
    +-  }
    +-  | tUNUMBER ':' tUNUMBER {
    +-      yyHour = $1;
    +-      yyMinutes = $3;
    +-      yyMeridian = MER24;
    +-  }
    +-  | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
    +-      yyHour = $1;
    +-      yyMinutes = $3;
    +-      yySeconds = $5;
    +-      yyMeridian = $6;
     -  }
     -  | tUNUMBER ':' tUNUMBER ':' tUNUMBER {
     -      yyHour = $1;
     -      yyMinutes = $3;
     -      yySeconds = $5;
    +-      yyMeridian = MER24;
     -  }
     -  ;
     -
    @@ lib/getdate.y: relunit   : tUNUMBER tYEAR_UNIT {
     -                  yyMinutes = $1 % 100;
     -                }
     -              yySeconds = 0;
    +-              yyMeridian = MER24;
     -            }
     -        }
    +-    }
    +-  ;
    +-
    +-o_merid   : /* NULL */
    +-    {
    +-      $$ = MER24;
    +-    }
    +-  | tMERIDIAN
    +-    {
    +-      $$ = $1;
          }
        ;
      
    @@ lib/getdate.y: static TABLE const UnitsTable[] = {
          { "next",             tUNUMBER,       2 },
          { "first",            tUNUMBER,       1 },
      /*  { "second",           tUNUMBER,       2 }, */
    +@@ lib/getdate.y: static int yyerror (MAYBE_UNUSED const char *s)
    +   return 0;
    + }
    + 
    +-static int ToHour (int Hours, MERIDIAN Meridian)
    +-{
    +-  switch (Meridian)
    +-    {
    +-    case MER24:
    +-      if (Hours < 0 || Hours > 23)
    +-  return -1;
    +-      return Hours;
    +-    case MERam:
    +-      if (Hours < 1 || Hours > 12)
    +-  return -1;
    +-      if (Hours == 12)
    +-  Hours = 0;
    +-      return Hours;
    +-    case MERpm:
    +-      if (Hours < 1 || Hours > 12)
    +-  return -1;
    +-      if (Hours == 12)
    +-  Hours = 0;
    +-      return Hours + 12;
    +-    default:
    +-      abort ();
    +-    }
    +-  /* NOTREACHED */
    +-}
    +-
    + static int ToYear (int Year)
    + {
    +   if (Year < 0)
    +@@ lib/getdate.y: static int LookupWord (char *buff)
    +     if (isupper (*p))
    +       *p = tolower (*p);
    + 
    +-  if (streq(buff, "am") || streq(buff, "a.m."))
    +-    {
    +-      yylval.Meridian = MERam;
    +-      return tMERIDIAN;
    +-    }
    +-  if (streq(buff, "pm") || streq(buff, "p.m."))
    +-    {
    +-      yylval.Meridian = MERpm;
    +-      return tMERIDIAN;
    +-    }
    +-
    +   /* See if we have an abbreviation for a month. */
    +   if (strlen (buff) == 3)
    +     abbrev = true;
     @@ lib/getdate.y: time_t get_date (const char *p, const time_t *now)
        yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
        yyMonth = tmp->tm_mon + 1;
    @@ lib/getdate.y: time_t get_date (const char *p, const time_t *now)
     -  yyHour = tmp->tm_hour;
     -  yyMinutes = tmp->tm_min;
     -  yySeconds = tmp->tm_sec;
    +-  yyMeridian = MER24;
     -  yyRelSeconds = 0;
     -  yyRelMinutes = 0;
     -  yyRelHour = 0;
    @@ lib/getdate.y: time_t get_date (const char *p, const time_t *now)
     -  if ((yyHaveTime != 0) ||
     -      ( (yyHaveRel != 0) && (yyHaveDate == 0) && (yyHaveDay == 0) ))
     -    {
    --      tm.tm_hour = yyHour;
    +-      tm.tm_hour = ToHour (yyHour, yyMeridian);
     -      if (tm.tm_hour < 0)
     -  return -1;
     -      tm.tm_min = yyMinutes;
 3:  64d5d8de !  2:  4e143c9f lib/getdate.y: Do not parse relative dates, such as 'yesterday'
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/getdate.y: Do not parse relative dates, such as 'yesterday'
    +    lib/getdate.y: Don't parse relative dates, such as 'yesterday'
     
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
 4:  0851afca =  3:  7812415b lib/getdate.y: Don't parse week days
 5:  8c581d5e =  4:  3908b9f9 lib/getdate.y: Remove unnecessary variable
 6:  4c923f93 !  5:  05ce266b lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
    @@ Metadata
      ## Commit message ##
         lib/getdate.y: Don't parse dates in local formats; just YYYY-MM-DD
     
    -    Signed-off-by: Alejandro Colomar <alx@kernel.org>
    -
      ## lib/getdate.y ##
     @@
      
    @@ lib/getdate.y
      #include "string/strspn/stpspn.h"
      
      
    +@@ lib/getdate.y: typedef struct _TABLE {
    + **  the %union very rarely.
    + */
    + static const char *yyInput;
    +-static int        yyHaveDate;
    + static int        yyDay;
    + static int        yyMonth;
    + static int        yyYear;
     @@ lib/getdate.y: static int       yyYear;
          int                   Number;
      }
    @@ lib/getdate.y: static int        yyYear;
      %type     <Number>        tSNUMBER tUNUMBER
      
      %%
    -@@ lib/getdate.y: item     : date {
    +@@ lib/getdate.y: spec     : /* NULL */
    +   | spec item
    +   ;
    + 
    +-item      : date {
    +-      yyHaveDate++;
    +-  }
    ++item      : date
        | number
        ;
      
    @@ lib/getdate.y: item      : date {
        ;
      
      number    : tUNUMBER
    +           {
    +-              yyHaveDate++;
    +               yyDay= ($1)%100;
    +               yyMonth= ($1/100)%100;
    +               yyYear = $1/10000;
     @@ lib/getdate.y: number   : tUNUMBER
      
      %%
    @@ lib/getdate.y: number    : tUNUMBER
      ^L
      
      
    -@@ lib/getdate.y: static int ToYear (int Year)
    -   return Year;
    +@@ lib/getdate.y: static int yyerror (MAYBE_UNUSED const char *s)
    +   return 0;
      }
      
    +-static int ToYear (int Year)
    +-{
    +-  if (Year < 0)
    +-    Year = -Year;
    +-
    +-  /* XPG4 suggests that years 00-68 map to 2000-2068, and
    +-     years 69-99 map to 1969-1999.  */
    +-  if (Year < 69)
    +-    Year += 2000;
    +-  else if (Year < 100)
    +-    Year += 1900;
    +-
    +-  return Year;
    +-}
    +-
     -static int LookupWord (char *buff)
     -{
     -  register char *p;
    @@ lib/getdate.y: yylex (void)
            if (c != '(')
        return *yyInput++;
            Count = 0;
    +@@ lib/getdate.y: time_t get_date (const char *p, const time_t *now)
    +   struct tm  tm;
    + 
    +   yyInput = p;
    +-  yyHaveDate = 0;
    + 
    +-  if (yyparse ()
    +-      || yyHaveDate > 1)
    ++  if (yyparse())
    +     return -1;
    + 
    +-  tm.tm_year = ToYear (yyYear) - TM_YEAR_ORIGIN;
    ++  tm.tm_year = yyYear - TM_YEAR_ORIGIN;
    +   tm.tm_mon = yyMonth - 1;
    +   tm.tm_mday = yyDay;
    +   tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
 7:  e385099d <  -:  -------- lib/getdate.y: Remove unnecessary variable
 8:  8928c17e <  -:  -------- lib/getdate.y: Don't parse 2-digit years as if 19xx/20xx years
 9:  a842f13b !  6:  ad501f36 lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/getdate.y: Don't parse a raw number; just a yyyy-mm-dd date
    +    lib/getdate.y: Don't parse a raw number; just a calendar date
     
         Our caller, strtoday(), already handles a raw number.
     
16:  51e704a0 =  7:  4811959b man/: Consistently express dates in standard format
17:  07e2690b =  8:  ea6be66b man/: Localized dates are not accepted anymore
18:  3ad0f396 !  9:  c225d27b lib/strtoday.c: strtoday(): Remove obsolete comment
    @@ Metadata
     Author: Alejandro Colomar <alx@kernel.org>
     
      ## Commit message ##
    -    lib/strtoday.c: strtoday(): Remove obsolete comment
    +    lib/strtoday.c: strtoday(): Replace obsolete comment
     
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
    @@ lib/strtoday.c
     - *        24-sep-72
     - *        24sep72
     - */
    - long
    - strtoday(const char *str)
    ++// string parse-to day-since-Epoch
    + long strtoday (const char *str)
      {
    +   time_t t;
 -:  -------- > 10:  1e8395be man/chage.1.xml: Update -d -E options
 -:  -------- > 11:  19f564e1 man/chage.1.xml: wfix
10:  2584f687 = 12:  81147960 lib/getdate.y: Reimplement in pure C
11:  233bb8d3 = 13:  8189d7b9 lib/getdate.y: Remove most yacc(1) stuff, which is unused
12:  90ed4c81 = 14:  4089e555 *: Get rid of yacc(1)
13:  218fdd58 ! 15:  94acdde9 lib/: Fix indentation and alignment
    @@ lib/getdate.c: static long  yyYear;
     
      ## lib/strtoday.c ##
     @@
    -  *        24-sep-72
    -  *        24sep72
    -  */
    + 
    + 
    + // string parse-to day-since-Epoch
     -long strtoday (const char *str)
     +long
     +strtoday(const char *str)
14:  c13c2ae4 = 16:  d1aaa378 lib/: get_date(): Remove unused parameter
15:  d570ef52 = 17:  7d7fe061 lib/getdate.c: Use strptime(3) to simplify
19:  4493cd24 = 18:  251c2f82 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
20:  e849314d = 19:  f2cb0dfa lib/strtoday.c: strtoday(): Remove obsolete comment
21:  55eab710 ! 20:  dd9646f3 lib/: Move get_date() to lib/strtoday.c
    @@ lib/strtoday.c
     +static time_t get_date(const char *s);
      
      
    - long
    + // string parse-to day-since-Epoch
     @@ lib/strtoday.c: strtoday(const char *str)
        }
        return t / DAY;
22:  e2475695 ! 21:  0da02c27 lib/strtoday.c: Actually return a date from get_date()
    @@ lib/strtoday.c
     +static long dategm(struct tm *tm);
      
      
    - long
    + // string parse-to day-since-Epoch
    +@@ lib/strtoday.c: long
      strtoday(const char *str)
      {
        long  d;
v4
$ git range-diff gd gh/gd2 gd2 
 1:  81147960 =  1:  81147960 lib/getdate.y: Reimplement in pure C
 2:  8189d7b9 =  2:  8189d7b9 lib/getdate.y: Remove most yacc(1) stuff, which is unused
 3:  4089e555 =  3:  4089e555 *: Get rid of yacc(1)
 4:  94acdde9 =  4:  94acdde9 lib/: Fix indentation and alignment
 5:  d1aaa378 =  5:  d1aaa378 lib/: get_date(): Remove unused parameter
 6:  7d7fe061 !  6:  da4419fb lib/getdate.c: Use strptime(3) to simplify
    @@ Metadata
      ## Commit message ##
         lib/getdate.c: Use strptime(3) to simplify
     
    +    The following trick:
    +
    +            t = 0;
    +            gmtime_r(&t, &tm);
    +
    +    is a clever way to clear the tm(3type) structure, and set it to use UTC.
    +
    +    We need to set it to set UTC with this trick, because strptime(3)
    +    doesn't set the timezone.  I (Alex) tried previously using
    +
    +            bzero(&tm, sizeof(tm));
    +            strptime("UTC", "%Z", &tm);
    +
    +    but glibc ignores the timezone, and musl (at least I tried in an Alpine
    +    container) seems to report an error.
    +
    +    The idea to use gmtime_r(3) was from lanodan.
    +
    +    Link: <https://inbox.sourceware.org/libc-alpha/Z_LqUgildoq33vI-@cloudsdale.the-delta.net.eu.org/T/#u>
    +    Cc: Iker Pedrosa <ipedrosa@redhat.com>
    +    Cc: Serge Hallyn <serge@hallyn.com>
    +    Cc: Rich Felker <dalias@libc.org>
    +    Co-authored-by: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/getdate.c ##
     @@
    + // SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
    ++// SPDX-FileCopyrightText: 2025, "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
    + // SPDX-License-Identifier: BSD-3-Clause
    + 
      
      #include <config.h>
      
    @@ lib/getdate.c
     -#include <limits.h>
      #include <stddef.h>
     -#include <string.h>
    -+#include <strings.h>
      #include <time.h>
      
     -#include "atoi/a2i/a2s.h"
    @@ lib/getdate.c
     +get_date(const char *s)
      {
     -  struct tm  tm;
    ++  time_t      t;
     +  struct tm   tm;
     +  const char  *p;
      
     -  if (parse_date(p) == -1)
    -+  bzero(&tm, sizeof(tm));
    -+
    -+  p = strptime("UTC", "%Z", &tm);
    -+  if (p == NULL || !streq(p, ""))
    ++  t = 0;
    ++  if (gmtime_r(&t, &tm) == NULL)
                return -1;
      
     -  tm.tm_year = yyYear - TM_YEAR_ORIGIN;
 7:  251c2f82 =  7:  f3bca071 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
 8:  f2cb0dfa =  8:  c2951f74 lib/strtoday.c: strtoday(): Remove obsolete comment
 9:  dd9646f3 !  9:  104f8efe lib/: Move get_date() to lib/strtoday.c
    @@ lib/Makefile.am: libshadow_la_SOURCES = \
      ## lib/getdate.c (deleted) ##
     @@
     -// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
    +-// SPDX-FileCopyrightText: 2025, "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
     -// SPDX-License-Identifier: BSD-3-Clause
     -
     -
     -#include <config.h>
     -
     -#include <stddef.h>
    --#include <strings.h>
     -#include <time.h>
     -
     -#include "getdate.h"
    @@ lib/getdate.c (deleted)
     -time_t
     -get_date(const char *s)
     -{
    +-  time_t      t;
     -  struct tm   tm;
     -  const char  *p;
     -
    --  bzero(&tm, sizeof(tm));
    --
    --  p = strptime("UTC", "%Z", &tm);
    --  if (p == NULL || !streq(p, ""))
    +-  t = 0;
    +-  if (gmtime_r(&t, &tm) == NULL)
     -          return -1;
     -
     -  p = strptime(s, "%F", &tm);
    @@ lib/strtoday.c
     +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko
     +// SPDX-FileCopyrightText: 2008, Nicolas François
     +// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
    ++// SPDX-FileCopyrightText: 2025, "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
     +// SPDX-License-Identifier: BSD-3-Clause
     +
      
    @@ lib/strtoday.c
      
     -#include <ctype.h>
     +#include <stddef.h>
    -+#include <strings.h>
     +#include <time.h>
      
      #include "atoi/str2i/str2s.h"
    @@ lib/strtoday.c: strtoday(const char *str)
     +static time_t
     +get_date(const char *s)
     +{
    ++  time_t      t;
     +  struct tm   tm;
     +  const char  *p;
     +
    -+  bzero(&tm, sizeof(tm));
    -+
    -+  p = strptime("UTC", "%Z", &tm);
    -+  if (p == NULL || !streq(p, ""))
    ++  t = 0;
    ++  if (gmtime_r(&t, &tm) == NULL)
     +          return -1;
     +
     +  p = strptime(s, "%F", &tm);
10:  0da02c27 ! 10:  56ee6b88 lib/strtoday.c: Actually return a date from get_date()
    @@ lib/strtoday.c: strtoday(const char *str)
     +static long
      get_date(const char *s)
      {
    -   struct tm   tm;
    +   time_t      t;
     @@ lib/strtoday.c: get_date(const char *s)
        if (p == NULL || !streq(p, ""))
                return -1;
v4b
$ git range-diff gd gh/gd2 gd2 
 1:  81147960 =  1:  81147960 lib/getdate.y: Reimplement in pure C
 2:  8189d7b9 =  2:  8189d7b9 lib/getdate.y: Remove most yacc(1) stuff, which is unused
 3:  4089e555 =  3:  4089e555 *: Get rid of yacc(1)
 4:  94acdde9 =  4:  94acdde9 lib/: Fix indentation and alignment
 5:  d1aaa378 =  5:  d1aaa378 lib/: get_date(): Remove unused parameter
 6:  da4419fb !  6:  01482ccd lib/getdate.c: Use strptime(3) to simplify
    @@ Commit message
         Cc: Serge Hallyn <serge@hallyn.com>
         Cc: Rich Felker <dalias@libc.org>
         Co-authored-by: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
    +    Signed-off-by: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/getdate.c ##
 7:  f3bca071 =  7:  9ab259e8 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
 8:  c2951f74 =  8:  91a0c5ad lib/strtoday.c: strtoday(): Remove obsolete comment
 9:  104f8efe =  9:  21219f96 lib/: Move get_date() to lib/strtoday.c
10:  56ee6b88 = 10:  1b7485a7 lib/strtoday.c: Actually return a date from get_date()
v5
  • Use "%Y-%m-%d" instead of "%F" with strptime(3). It seems "%F" is portable only with strftime(3), but not strptime(3).
$ git range-diff gd gh/gd2 gd2 
 1:  81147960 =  1:  81147960 lib/getdate.y: Reimplement in pure C
 2:  8189d7b9 =  2:  8189d7b9 lib/getdate.y: Remove most yacc(1) stuff, which is unused
 3:  4089e555 =  3:  4089e555 *: Get rid of yacc(1)
 4:  94acdde9 =  4:  94acdde9 lib/: Fix indentation and alignment
 5:  d1aaa378 =  5:  d1aaa378 lib/: get_date(): Remove unused parameter
 6:  01482ccd !  6:  86df067c lib/getdate.c: Use strptime(3) to simplify
    @@ lib/getdate.c
     -  tm.tm_mday = yyDay;
     -  tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
     -  tm.tm_isdst = 0;
    -+  p = strptime(s, "%F", &tm);
    ++  p = strptime(s, "%Y-%m-%d", &tm);
     +  if (p == NULL || !streq(p, ""))
     +          return -1;
      
 7:  9ab259e8 =  7:  5ae8c03e lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
 8:  91a0c5ad =  8:  2c9c8c67 lib/strtoday.c: strtoday(): Remove obsolete comment
 9:  21219f96 !  9:  2b30c904 lib/: Move get_date() to lib/strtoday.c
    @@ lib/getdate.c (deleted)
     -  if (gmtime_r(&t, &tm) == NULL)
     -          return -1;
     -
    --  p = strptime(s, "%F", &tm);
    +-  p = strptime(s, "%Y-%m-%d", &tm);
     -  if (p == NULL || !streq(p, ""))
     -          return -1;
     -
    @@ lib/strtoday.c: strtoday(const char *str)
     +  if (gmtime_r(&t, &tm) == NULL)
     +          return -1;
     +
    -+  p = strptime(s, "%F", &tm);
    ++  p = strptime(s, "%Y-%m-%d", &tm);
     +  if (p == NULL || !streq(p, ""))
     +          return -1;
     +
10:  1b7485a7 = 10:  e19d610b lib/strtoday.c: Actually return a date from get_date()
v5b
  • Rebase
$ git range-diff gh/gd..gh/gd2 gd..gd2
 1:  81147960 =  1:  8d14ef8f lib/getdate.y: Reimplement in pure C
 2:  8189d7b9 =  2:  af4f550f lib/getdate.y: Remove most yacc(1) stuff, which is unused
 3:  4089e555 =  3:  c5c76f56 *: Get rid of yacc(1)
 4:  94acdde9 =  4:  18c0758c lib/: Fix indentation and alignment
 5:  d1aaa378 =  5:  7e38b838 lib/: get_date(): Remove unused parameter
 6:  86df067c =  6:  ff09c2cc lib/getdate.c: Use strptime(3) to simplify
 7:  5ae8c03e =  7:  09bef14d lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
 8:  2c9c8c67 =  8:  ef4c4c54 lib/strtoday.c: strtoday(): Remove obsolete comment
 9:  2b30c904 =  9:  c32e093d lib/: Move get_date() to lib/strtoday.c
10:  e19d610b = 10:  59cf0db1 lib/strtoday.c: Actually return a date from get_date()
v5c
  • Rebase
$ git range-diff 8d14ef8f^..gh/gd2 shadow/master..gd2
 1:  8d14ef8f =  1:  e7ceca78 lib/getdate.y: Reimplement in pure C
 2:  af4f550f =  2:  d07aeb7e lib/getdate.y: Remove most yacc(1) stuff, which is unused
 3:  c5c76f56 =  3:  00a534d0 *: Get rid of yacc(1)
 4:  18c0758c =  4:  c721683e lib/: Fix indentation and alignment
 5:  7e38b838 =  5:  2b89ffc8 lib/: get_date(): Remove unused parameter
 6:  ff09c2cc =  6:  64841fa6 lib/getdate.c: Use strptime(3) to simplify
 7:  09bef14d =  7:  ab11661f lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
 8:  ef4c4c54 =  8:  f9881220 lib/strtoday.c: strtoday(): Remove obsolete comment
 9:  c32e093d =  9:  47881cc0 lib/: Move get_date() to lib/strtoday.c
10:  59cf0db1 = 10:  8170041f lib/strtoday.c: Actually return a date from get_date()
v5d
  • Fix typo in intermediate commit.
$ git rd
 1:  e7ceca78 =  1:  e7ceca78 lib/getdate.y: Reimplement in pure C
 2:  d07aeb7e =  2:  d07aeb7e lib/getdate.y: Remove most yacc(1) stuff, which is unused
 3:  00a534d0 =  3:  00a534d0 *: Get rid of yacc(1)
 4:  c721683e =  4:  c721683e lib/: Fix indentation and alignment
 5:  2b89ffc8 !  5:  4905ddcd lib/: get_date(): Remove unused parameter
    @@ lib/getdate.c: static int parse_date(const char *s);
      
      time_t
     -get_date(const char *p, const time_t *now)
    -+get_date(const char *s);
    ++get_date(const char *s)
      {
        struct tm  tm;
      
 6:  64841fa6 !  6:  44c67113 lib/getdate.c: Use strptime(3) to simplify
    @@ lib/getdate.c
      
      
      time_t
    --get_date(const char *s);
    -+get_date(const char *s)
    + get_date(const char *s)
      {
     -  struct tm  tm;
     +  time_t      t;
 7:  ab11661f =  7:  6670525e lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
 8:  f9881220 =  8:  cc5ca7e1 lib/strtoday.c: strtoday(): Remove obsolete comment
 9:  47881cc0 =  9:  41e48fc2 lib/: Move get_date() to lib/strtoday.c
10:  8170041f = 10:  3ea77dfa lib/strtoday.c: Actually return a date from get_date()
v5e
  • Squash first 3 commits.
$ git range-diff shadow/master gh/gd2 gd2 
 1:  e7ceca78 <  -:  -------- lib/getdate.y: Reimplement in pure C
 2:  d07aeb7e <  -:  -------- lib/getdate.y: Remove most yacc(1) stuff, which is unused
 3:  00a534d0 <  -:  -------- *: Get rid of yacc(1)
 -:  -------- >  1:  e90301c5 lib/getdate.*: Reimplement in pure C
 4:  c721683e =  2:  7de7cb27 lib/: Fix indentation and alignment
 5:  4905ddcd =  3:  937b51cc lib/: get_date(): Remove unused parameter
 6:  44c67113 =  4:  252589fe lib/getdate.c: Use strptime(3) to simplify
 7:  6670525e =  5:  39308060 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
 8:  cc5ca7e1 =  6:  a956e581 lib/strtoday.c: strtoday(): Remove obsolete comment
 9:  41e48fc2 =  7:  f58ecd28 lib/: Move get_date() to lib/strtoday.c
10:  3ea77dfa =  8:  ea05264d lib/strtoday.c: Actually return a date from get_date()
$ git diff gh/gd2 gd2
$ 
v6
  • Rebase
$ git rd
1:  e90301c5 = 1:  ad55facb lib/getdate.*: Reimplement in pure C
2:  7de7cb27 = 2:  b9c87d84 lib/: Fix indentation and alignment
3:  937b51cc = 3:  05868a77 lib/: get_date(): Remove unused parameter
4:  252589fe = 4:  1a9ffa71 lib/getdate.c: Use strptime(3) to simplify
5:  39308060 ! 5:  975cf856 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
    @@ lib/strtoday.c
      #include "prototypes.h"
     -#include "string/ctype/strisascii/strisdigit.h"
      #include "string/strcmp/streq.h"
    - #include "string/strspn/stpspn.h"
    +-#include "string/strcmp/strprefix.h"
    +-#include "string/strspn/stpspn.h"
      
    -@@
    + 
    + // string parse-to day-since-Epoch
      long
      strtoday(const char *str)
      {
    @@ lib/strtoday.c: strtoday(const char *str)
        /* If a numerical value is provided, this is already a number of
         * days since EPOCH.
         */
    --  if ('-' == *s) {
    --          s++;
    --  }
    +-  s = strprefix(s, "-") ?: s;
     -  s = stpspn(s, " ");
     -  if (strisdigit(s)) {
     -          long retdate;
6:  a956e581 = 6:  b40429e8 lib/strtoday.c: strtoday(): Remove obsolete comment
7:  f58ecd28 ! 7:  ea24f5cd lib/: Move get_date() to lib/strtoday.c
    @@ lib/strtoday.c
     +#include "defines.h"
      #include "prototypes.h"
      #include "string/strcmp/streq.h"
    --#include "string/strspn/stpspn.h"
    -+
    -+
    + 
    + 
     +static time_t get_date(const char *s);
    - 
    - 
    ++
    ++
      // string parse-to day-since-Epoch
    + long
    + strtoday(const char *str)
     @@ lib/strtoday.c: strtoday(const char *str)
        }
        return t / DAY;
8:  ea05264d = 8:  0bda14b3 lib/strtoday.c: Actually return a date from get_date()
v6b
  • Rebase
$ git rd
1:  ad55facb = 1:  e025c338 lib/getdate.*: Reimplement in pure C
2:  b9c87d84 = 2:  e3af6fc1 lib/: Fix indentation and alignment
3:  05868a77 = 3:  bfe8b2d4 lib/: get_date(): Remove unused parameter
4:  1a9ffa71 = 4:  1708dc8d lib/getdate.c: Use strptime(3) to simplify
5:  975cf856 = 5:  e827325f lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
6:  b40429e8 = 6:  e48d20d6 lib/strtoday.c: strtoday(): Remove obsolete comment
7:  ea24f5cd = 7:  94550e9a lib/: Move get_date() to lib/strtoday.c
8:  0bda14b3 = 8:  56a73ad7 lib/strtoday.c: Actually return a date from get_date()
v6c
  • Fix intermediate commit. I had renamed a parameter without updating its use. [@hallyn]
$ git rd
1:  e025c338 = 1:  e025c338 lib/getdate.*: Reimplement in pure C
2:  e3af6fc1 = 2:  e3af6fc1 lib/: Fix indentation and alignment
3:  bfe8b2d4 ! 3:  672c4294 lib/: get_date(): Remove unused parameter
    @@ Metadata
      ## Commit message ##
         lib/: get_date(): Remove unused parameter
     
    +    And rename the remaining parameter.
    +
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/getdate.c ##
    @@ lib/getdate.c: static int parse_date(const char *s);
      {
        struct tm  tm;
      
    +-  if (parse_date(p) == -1)
    ++  if (parse_date(s) == -1)
    +           return -1;
    + 
    +   tm.tm_year = yyYear - TM_YEAR_ORIGIN;
     
      ## lib/getdate.h ##
     @@
4:  1708dc8d ! 4:  d36db9c4 lib/getdate.c: Use strptime(3) to simplify
    @@ lib/getdate.c
     +  struct tm   tm;
     +  const char  *p;
      
    --  if (parse_date(p) == -1)
    +-  if (parse_date(s) == -1)
     +  t = 0;
     +  if (gmtime_r(&t, &tm) == NULL)
                return -1;
5:  e827325f = 5:  4485e647 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
6:  e48d20d6 = 6:  3bf73476 lib/strtoday.c: strtoday(): Remove obsolete comment
7:  94550e9a = 7:  4c7e9c7d lib/: Move get_date() to lib/strtoday.c
8:  56a73ad7 = 8:  4d27d0cc lib/strtoday.c: Actually return a date from get_date()
v6d
  • Rebase
$ git rd
1:  e025c338 = 1:  81db5392 lib/getdate.*: Reimplement in pure C
2:  e3af6fc1 = 2:  a768149f lib/: Fix indentation and alignment
3:  672c4294 = 3:  6bc74ff9 lib/: get_date(): Remove unused parameter
4:  d36db9c4 = 4:  a6d4918c lib/getdate.c: Use strptime(3) to simplify
5:  4485e647 ! 5:  f2d14363 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
    @@ Commit message
     
      ## lib/strtoday.c ##
     @@
    - #include "atoi/str2i/str2s.h"
    + #include "atoi/str2i.h"
      #include "getdate.h"
      #include "prototypes.h"
     -#include "string/ctype/strisascii/strisdigit.h"
6:  3bf73476 = 6:  177fcfe5 lib/strtoday.c: strtoday(): Remove obsolete comment
7:  4c7e9c7d ! 7:  f2b8b380 lib/: Move get_date() to lib/strtoday.c
    @@ lib/strtoday.c
     +#include <stddef.h>
     +#include <time.h>
      
    - #include "atoi/str2i/str2s.h"
    + #include "atoi/str2i.h"
     -#include "getdate.h"
     +#include "defines.h"
      #include "prototypes.h"
8:  4d27d0cc = 8:  2b02f1b5 lib/strtoday.c: Actually return a date from get_date()
v6e
  • Rebase
$ git range-diff 81db53927634^..gh/gd2 shadow/master..gd2 
1:  81db5392 = 1:  61d6f7bd lib/getdate.*: Reimplement in pure C
2:  a768149f = 2:  f3daf1ec lib/: Fix indentation and alignment
3:  6bc74ff9 = 3:  953e9e74 lib/: get_date(): Remove unused parameter
4:  a6d4918c = 4:  0d9b3ba0 lib/getdate.c: Use strptime(3) to simplify
5:  f2d14363 = 5:  0d36a58e lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
6:  177fcfe5 = 6:  2b871947 lib/strtoday.c: strtoday(): Remove obsolete comment
7:  f2b8b380 = 7:  3450cd0c lib/: Move get_date() to lib/strtoday.c
8:  2b02f1b5 = 8:  263b1fe1 lib/strtoday.c: Actually return a date from get_date()
v6f
  • Rebase
$ git rd
1:  61d6f7bd = 1:  e31d2977 lib/getdate.*: Reimplement in pure C
2:  f3daf1ec = 2:  a1d94c76 lib/: Fix indentation and alignment
3:  953e9e74 = 3:  843bbac7 lib/: get_date(): Remove unused parameter
4:  0d9b3ba0 = 4:  802c9610 lib/getdate.c: Use strptime(3) to simplify
5:  0d36a58e = 5:  778ec009 lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
6:  2b871947 = 6:  d52d1a2d lib/strtoday.c: strtoday(): Remove obsolete comment
7:  3450cd0c = 7:  b47ca487 lib/: Move get_date() to lib/strtoday.c
8:  263b1fe1 = 8:  0d426700 lib/strtoday.c: Actually return a date from get_date()
v6g
  • Rebase
$ git rd
1:  e31d2977 = 1:  efbbb057 lib/getdate.*: Reimplement in pure C
2:  a1d94c76 = 2:  edcc515a lib/: Fix indentation and alignment
3:  843bbac7 = 3:  61a5fff5 lib/: get_date(): Remove unused parameter
4:  802c9610 = 4:  98005517 lib/getdate.c: Use strptime(3) to simplify
5:  778ec009 = 5:  1bf48bda lib/strtoday.c: strtoday(): Attempt parsing with str2sl() directly
6:  d52d1a2d = 6:  bfaa2123 lib/strtoday.c: strtoday(): Remove obsolete comment
7:  b47ca487 = 7:  cea1ff50 lib/: Move get_date() to lib/strtoday.c
8:  0d426700 = 8:  727c0bb4 lib/strtoday.c: Actually return a date from get_date()

@alejandro-colomar alejandro-colomar force-pushed the gd2 branch 3 times, most recently from 4586d99 to 622a851 Compare February 18, 2025 11:23
@zeha
Copy link
Contributor

zeha commented Feb 18, 2025

Nice. However this seems to introduce some warnings:

  CC       getdate.o
getdate.y: In function ‘LookupWord’:
getdate.y:290:7: warning: unused variable ‘i’ [-Wunused-variable]
  290 |   int i;
      |       ^
getdate.y:288:18: warning: unused variable ‘q’ [-Wunused-variable]
  288 |   register char *q;
      |                  ^
getdate.y: In function ‘get_date’:
getdate.y:390:17: warning: variable ‘tm0’ set but not used [-Wunused-but-set-variable]
  390 |   struct tm tm, tm0, *tmp;
      |                 ^~~

@alejandro-colomar
Copy link
Collaborator Author

Nice. However this seems to introduce some warnings:

  CC       getdate.o
getdate.y: In function ‘LookupWord’:
getdate.y:290:7: warning: unused variable ‘i’ [-Wunused-variable]
  290 |   int i;
      |       ^
getdate.y:288:18: warning: unused variable ‘q’ [-Wunused-variable]
  288 |   register char *q;
      |                  ^
getdate.y: In function ‘get_date’:
getdate.y:390:17: warning: variable ‘tm0’ set but not used [-Wunused-but-set-variable]
  390 |   struct tm tm, tm0, *tmp;
      |                 ^~~

Thanks! I fixed those. I might have introduced more, though. :)

@alejandro-colomar alejandro-colomar force-pushed the gd2 branch 4 times, most recently from 0002748 to c42cb74 Compare February 18, 2025 12:07
@alejandro-colomar alejandro-colomar force-pushed the gd2 branch 4 times, most recently from c6e19a1 to 3b362ac Compare February 18, 2025 13:14
@alejandro-colomar alejandro-colomar changed the title Put get_date() on a diet yacc(1) is a dead language; bury it deep in the ground Feb 18, 2025
@alejandro-colomar alejandro-colomar force-pushed the gd2 branch 2 times, most recently from 749273c to 1586985 Compare February 18, 2025 14:59
@alejandro-colomar alejandro-colomar force-pushed the gd2 branch 3 times, most recently from d6146f0 to b165e9e Compare February 19, 2025 00:03
@zeha
Copy link
Contributor

zeha commented Feb 19, 2025

I guess in configure.ac you can drop AC_PROG_YACC et al?

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Feb 19, 2025 via email

@alejandro-colomar alejandro-colomar force-pushed the gd2 branch 3 times, most recently from 7bcbf10 to f691412 Compare February 19, 2025 08:27
@alejandro-colomar
Copy link
Collaborator Author

Wow! 1k down. :)

Interested parties, please test and complain if there's anything that affects you negatively. ;)

Observers, feel free to suggest further simplification, if it's possible. I think I got rid of everything I could.

Cc: @leegarrett
Cc: @zeha
Cc: @kenion
Cc: @jubalh
Cc: @ikerexxe
Cc: @hallyn
Cc: @BrianInglis

alejandro-colomar added a commit to alejandro-colomar/shadow that referenced this pull request May 27, 2025
get_date() doesn't treat "" as a date anymore, so the comment is
obsolete.  We still need the code, though, as for example usermod(8)
uses an empty string as a synonym for -1.

Link: <shadow-maint#1217 (comment)>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@hallyn
Copy link
Member

hallyn commented May 30, 2025

I don't like how this series progresses (for instance, patch 2 seems like it should just be squashed with 1, and patch 4 changes the first get_date argument name without changing its users, so that it cannot compile until get_date gets removed, and then re-added with different code later.)

But the end result seems ok.

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented May 30, 2025

@hallyn

I don't like how this series progresses (for instance, patch 2 seems like it should just be squashed with 1, and patch 4 changes the first get_date argument name without changing its users, so that it cannot compile until get_date gets removed, and then re-added with different code later.)

But the end result seems ok.

About patch 2, it is on purpose, and I've documented why here:
#1217 (comment).

About patch 4: You're right; I didn't realize. That's something I should fix. BTW, it's patch 3, I think.

alejandro-colomar added a commit to alejandro-colomar/shadow that referenced this pull request May 30, 2025
get_date() doesn't treat "" as a date anymore, so the comment is
obsolete.  We still need the code, though, as for example usermod(8)
uses an empty string as a synonym for -1.

Link: <shadow-maint#1217 (comment)>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@hallyn
Copy link
Member

hallyn commented May 30, 2025

@hallyn

I don't like how this series progresses (for instance, patch 2 seems like it should just be squashed with 1, and patch 4 changes the first get_date argument name without changing its users, so that it cannot compile until get_date gets removed, and then re-added with different code later.)
But the end result seems ok.

About patch 2, it is on purpose, and I've documented why here: #1217 (comment).

About patch 4: You're right; I didn't realize. That's something I should fix. BTW, it's patch 3, I think.

I assumed it was something like that, but unfortunately it doesnt' show up when you do a wget https://github.com/shadow-maint/shadow/pull/1217.patch :)

@hallyn
Copy link
Member

hallyn commented May 30, 2025

Well, once you resolve the conflicts, happy to merge. Not worth over-thinking I suppose.

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented May 30, 2025

Well, once you resolve the conflicts, happy to merge. Not worth over-thinking I suppose.

Thanks! I'll wait for Monday, since I want @ikerexxe to merge his tests first.

I'll rebase everything anyway, so that you can merge other PRs if you want.

alejandro-colomar added a commit to alejandro-colomar/shadow that referenced this pull request May 30, 2025
get_date() doesn't treat "" as a date anymore, so the comment is
obsolete.  We still need the code, though, as for example usermod(8)
uses an empty string as a synonym for -1.

Link: <shadow-maint#1217 (comment)>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
alejandro-colomar added a commit to alejandro-colomar/shadow that referenced this pull request May 30, 2025
get_date() doesn't treat "" as a date anymore, so the comment is
obsolete.  We still need the code, though, as for example usermod(8)
uses an empty string as a synonym for -1.

Link: <shadow-maint#1217 (comment)>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar alejandro-colomar force-pushed the gd2 branch 2 times, most recently from 263b1fe to 0d42670 Compare May 30, 2025 21:31
alejandro-colomar added a commit to alejandro-colomar/shadow that referenced this pull request May 30, 2025
get_date() doesn't treat "" as a date anymore, so the comment is
obsolete.  We still need the code, though, as for example usermod(8)
uses an empty string as a synonym for -1.

Link: <shadow-maint#1217 (comment)>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
alejandro-colomar and others added 8 commits May 31, 2025 00:57
This removes all yacc(1) code from this project.  Add copyright and
license, since there remains nothing of the original code.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
And rename the remaining parameter.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
The following trick:

	t = 0;
	gmtime_r(&t, &tm);

is a clever way to clear the tm(3type) structure, and set it to use UTC.

We need to set it to set UTC with this trick, because strptime(3)
doesn't set the timezone.  I (Alex) tried previously using

	bzero(&tm, sizeof(tm));
	strptime("UTC", "%Z", &tm);

but glibc ignores the timezone, and musl (at least I tried in an Alpine
container) seems to report an error.

The idea to use gmtime_r(3) was from lanodan.

Link: <https://inbox.sourceware.org/libc-alpha/Z_LqUgildoq33vI-@cloudsdale.the-delta.net.eu.org/T/#u>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Rich Felker <dalias@libc.org>
Co-authored-by: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
Signed-off-by: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
If it fails, let's fall back to get_date().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
get_date() doesn't treat "" as a date anymore, so the comment is
obsolete.  We still need the code, though, as for example usermod(8)
uses an empty string as a synonym for -1.

Link: <shadow-maint#1217 (comment)>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Copy link
Collaborator

@ikerexxe ikerexxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Let's merge this one first, and then rebase and merge #1233

@ikerexxe ikerexxe merged commit 69762b6 into shadow-maint:master Jun 2, 2025
10 checks passed
ikerexxe pushed a commit that referenced this pull request Jun 2, 2025
get_date() doesn't treat "" as a date anymore, so the comment is
obsolete.  We still need the code, though, as for example usermod(8)
uses an empty string as a synonym for -1.

Link: <#1217 (comment)>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar alejandro-colomar deleted the gd2 branch June 2, 2025 09:25
ikerexxe pushed a commit to ikerexxe/shadow that referenced this pull request Jun 6, 2025
get_date() doesn't treat "" as a date anymore, so the comment is
obsolete.  We still need the code, though, as for example usermod(8)
uses an empty string as a synonym for -1.

Link: <shadow-maint#1217 (comment)>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants