bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] parse-datetime: simplify test for mktime failure


From: Paul Eggert
Subject: [PATCH] parse-datetime: simplify test for mktime failure
Date: Sat, 3 Nov 2018 23:33:14 -0700

* lib/parse-datetime.y (mktime_ok): Simplify.
Remove args TZ and T; no longer needed.  Callers changed.
---
 ChangeLog            |  4 ++++
 lib/parse-datetime.y | 29 ++++++++++++-----------------
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b23f6e0df..e02140743 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2018-11-03  Paul Eggert  <address@hidden>
 
+       parse-datetime: simplify test for mktime failure
+       * lib/parse-datetime.y (mktime_ok): Simplify.
+       Remove args TZ and T; no longer needed.  Callers changed.
+
        posixtm: simplify test for mktime failure
        * lib/posixtm.c (posixtime): Simplify.
 
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
index aad5be834..4453b9a87 100644
--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -1554,24 +1554,17 @@ yyerror (parser_control const *pc _GL_UNUSED,
   return 0;
 }
 
-/* In timezone TZ, if *TM0 is the old and *TM1 is the new value of a
-   struct tm after passing it to mktime_z, return true if it's OK that
-   mktime_z returned T.  It's not OK if *TM0 has out-of-range
-   members.  */
+/* If *TM0 is the old and *TM1 is the new value of a struct tm after
+   passing it to mktime_z, return true if it's OK.  It's not OK if
+   mktime failed or if *TM0 has out-of-range mainline members.
+   The caller should set TM1->tm_wday to -1 before calling mktime,
+   as a negative tm_wday is how mktime failure is inferred.  */
 
 static bool
-mktime_ok (timezone_t tz, struct tm const *tm0, struct tm const *tm1, time_t t)
+mktime_ok (struct tm const *tm0, struct tm const *tm1)
 {
-  struct tm ltm;
-  if (t == (time_t) -1)
-    {
-      /* Guard against falsely reporting an error when parsing a
-         timestamp that happens to equal (time_t) -1, on a host that
-         supports such a timestamp.  */
-      tm1 = localtime_rz (tz, &t, &ltm);
-      if (!tm1)
-        return false;
-    }
+  if (tm1->tm_wday < 0)
+    return false;
 
   return ! ((tm0->tm_sec ^ tm1->tm_sec)
             | (tm0->tm_min ^ tm1->tm_min)
@@ -2046,10 +2039,11 @@ parse_datetime2 (struct timespec *result, char const *p,
       tm0.tm_mon = tm.tm_mon;
       tm0.tm_year = tm.tm_year;
       tm0.tm_isdst = tm.tm_isdst;
+      tm.tm_wday = -1;
 
       Start = mktime_z (tz, &tm);
 
-      if (! mktime_ok (tz, &tm0, &tm, Start))
+      if (! mktime_ok (&tm0, &tm))
         {
           bool repaired = false;
           bool time_zone_seen = pc.zones_seen != 0;
@@ -2082,8 +2076,9 @@ parse_datetime2 (struct timespec *result, char const *p,
               tm.tm_mon = tm0.tm_mon;
               tm.tm_year = tm0.tm_year;
               tm.tm_isdst = tm0.tm_isdst;
+              tm.tm_wday = -1;
               Start = mktime_z (tz2, &tm);
-              repaired = mktime_ok (tz2, &tm0, &tm, Start);
+              repaired = mktime_ok (&tm0, &tm);
               tzfree (tz2);
             }
 
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]