* [PATCH 1/2] nstrftime: simplify test for mktime failure
@ 2018-11-04 6:05 Paul Eggert
2018-11-04 6:05 ` [PATCH 2/2] posixtm: " Paul Eggert
0 siblings, 1 reply; 2+ messages in thread
From: Paul Eggert @ 2018-11-04 6:05 UTC (permalink / raw
To: bug-gnulib; +Cc: Paul Eggert
* lib/nstrftime.c (__strftime_internal): Simplify.
---
ChangeLog | 5 +++++
lib/nstrftime.c | 22 ++--------------------
2 files changed, 7 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bbf379b8c..cd9d8b83b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-03 Paul Eggert <eggert@cs.ucla.edu>
+
+ nstrftime: simplify test for mktime failure
+ * lib/nstrftime.c (__strftime_internal): Simplify.
+
2018-11-02 Paul Eggert <eggert@cs.ucla.edu>
gnulib-common.m4: port _Noreturn to C++
diff --git a/lib/nstrftime.c b/lib/nstrftime.c
index e55cfda0a..61ac84b0d 100644
--- a/lib/nstrftime.c
+++ b/lib/nstrftime.c
@@ -1438,28 +1438,10 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
# endif
ltm = *tp;
+ ltm.tm_wday = -1;
lt = mktime_z (tz, <m);
-
- if (lt == (time_t) -1)
- {
- /* mktime returns -1 for errors, but -1 is also a
- valid time_t value. Check whether an error really
- occurred. */
- struct tm tm;
-
- if (! localtime_rz (tz, <, &tm)
- || ((ltm.tm_sec ^ tm.tm_sec)
- | (ltm.tm_min ^ tm.tm_min)
- | (ltm.tm_hour ^ tm.tm_hour)
- | (ltm.tm_mday ^ tm.tm_mday)
- | (ltm.tm_mon ^ tm.tm_mon)
- | (ltm.tm_year ^ tm.tm_year)))
- break;
- }
-
- if (! localtime_rz (0, <, >m))
+ if (ltm.tm_wday < 0 || ! localtime_rz (0, <, >m))
break;
-
diff = tm_diff (<m, >m);
}
#endif
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] posixtm: simplify test for mktime failure
2018-11-04 6:05 [PATCH 1/2] nstrftime: simplify test for mktime failure Paul Eggert
@ 2018-11-04 6:05 ` Paul Eggert
0 siblings, 0 replies; 2+ messages in thread
From: Paul Eggert @ 2018-11-04 6:05 UTC (permalink / raw
To: bug-gnulib; +Cc: Paul Eggert
* lib/posixtm.c (posixtime): Simplify.
---
ChangeLog | 3 +++
lib/posixtm.c | 26 +++++++++-----------------
2 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cd9d8b83b..b23f6e0df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2018-11-03 Paul Eggert <eggert@cs.ucla.edu>
+ posixtm: simplify test for mktime failure
+ * lib/posixtm.c (posixtime): Simplify.
+
nstrftime: simplify test for mktime failure
* lib/nstrftime.c (__strftime_internal): Simplify.
diff --git a/lib/posixtm.c b/lib/posixtm.c
index 4e8125cc7..b3934b0ec 100644
--- a/lib/posixtm.c
+++ b/lib/posixtm.c
@@ -176,7 +176,6 @@ posixtime (time_t *p, const char *s, unsigned int syntax_bits)
{
struct tm tm0;
struct tm tm1;
- struct tm const *tm;
time_t t;
if (! posix_time_parse (&tm0, s, syntax_bits))
@@ -188,30 +187,23 @@ posixtime (time_t *p, const char *s, unsigned int syntax_bits)
tm1.tm_mday = tm0.tm_mday;
tm1.tm_mon = tm0.tm_mon;
tm1.tm_year = tm0.tm_year;
+ tm1.tm_wday = -1;
tm1.tm_isdst = -1;
t = mktime (&tm1);
- if (t != (time_t) -1)
- tm = &tm1;
- else
- {
- /* mktime returns -1 for errors, but -1 is also a valid time_t
- value. Check whether an error really occurred. */
- tm = localtime (&t);
- if (! tm)
- return false;
- }
+ if (tm1.tm_wday < 0)
+ return false;
/* Reject dates like "September 31" and times like "25:61".
However, allow a seconds count of 60 even in time zones that do
not support leap seconds, treating it as the following second;
POSIX requires this. */
- if ((tm0.tm_year ^ tm->tm_year)
- | (tm0.tm_mon ^ tm->tm_mon)
- | (tm0.tm_mday ^ tm->tm_mday)
- | (tm0.tm_hour ^ tm->tm_hour)
- | (tm0.tm_min ^ tm->tm_min)
- | (tm0.tm_sec ^ tm->tm_sec))
+ if ((tm0.tm_year ^ tm1.tm_year)
+ | (tm0.tm_mon ^ tm1.tm_mon)
+ | (tm0.tm_mday ^ tm1.tm_mday)
+ | (tm0.tm_hour ^ tm1.tm_hour)
+ | (tm0.tm_min ^ tm1.tm_min)
+ | (tm0.tm_sec ^ tm1.tm_sec))
{
/* Any mismatch without 60 in the tm_sec field is invalid. */
if (tm0.tm_sec != 60)
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-11-04 6:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-04 6:05 [PATCH 1/2] nstrftime: simplify test for mktime failure Paul Eggert
2018-11-04 6:05 ` [PATCH 2/2] posixtm: " Paul Eggert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).