diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-02-03 01:05:29 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-02-03 01:05:29 +0000 |
commit | b5ef404e0897450bbe1caaff867d8daf40ba0e35 (patch) | |
tree | a0dc75b233c00557b16c9150800c3f77fef1986d | |
parent | 352b06fdbf0dc508758beabfc4809b7115a4bfd2 (diff) | |
download | glibc-b5ef404e0897450bbe1caaff867d8daf40ba0e35.tar.gz glibc-b5ef404e0897450bbe1caaff867d8daf40ba0e35.tar.xz glibc-b5ef404e0897450bbe1caaff867d8daf40ba0e35.zip |
Update.
2002-02-02 Paul Eggert <eggert@twinsun.com> * src/mktime.c [defined DEBUG && STDC_HEADERS]: Include <string.h>. (__mktime_internal): If no tm_isdst is requested, prefer solutions with tm_isdst > 0 when the requested time falls within a spring-forward gap [PR libc/2894].
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | time/mktime.c | 20 |
2 files changed, 21 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog index c140a1d873..b8f57104cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-02-02 Paul Eggert <eggert@twinsun.com> + + * src/mktime.c [defined DEBUG && STDC_HEADERS]: Include <string.h>. + (__mktime_internal): If no tm_isdst is requested, prefer solutions + with tm_isdst > 0 when the requested time falls within a + spring-forward gap [PR libc/2894]. + 2002-02-03 Andreas Schwab <schwab@suse.de> * stdio-common/tst-rndseek.c: Increase timeout. diff --git a/time/mktime.c b/time/mktime.c index 7cfd297037..5f3f3f23f8 100644 --- a/time/mktime.c +++ b/time/mktime.c @@ -49,6 +49,7 @@ # include <stdio.h> # if STDC_HEADERS # include <stdlib.h> +# include <string.h> # endif /* Make it work even if the system's libc has its own mktime routine. */ # define mktime my_mktime @@ -236,6 +237,9 @@ __mktime_internal (struct tm *tp, int year_requested = tp->tm_year; int isdst = tp->tm_isdst; + /* 1 if the previous probe was DST. */ + int dst2; + /* Ensure that mon is in range, and set year accordingly. */ int mon_remainder = mon % 12; int negative_mon_remainder = mon_remainder < 0; @@ -270,20 +274,24 @@ __mktime_internal (struct tm *tp, tm.tm_yday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0; t0 = ydhms_tm_diff (year, yday, hour, min, sec, &tm); - for (t = t1 = t2 = t0 + *offset; + for (t = t1 = t2 = t0 + *offset, dst2 = 0; (dt = ydhms_tm_diff (year, yday, hour, min, sec, ranged_convert (convert, &t, &tm))); - t1 = t2, t2 = t, t += dt) + t1 = t2, t2 = t, t += dt, dst2 = tm.tm_isdst != 0) if (t == t1 && t != t2 - && (isdst < 0 || tm.tm_isdst < 0 - || (isdst != 0) != (tm.tm_isdst != 0))) + && (tm.tm_isdst < 0 + || (isdst < 0 + ? dst2 <= (tm.tm_isdst != 0) + : (isdst != 0) != (tm.tm_isdst != 0)))) /* We can't possibly find a match, as we are oscillating between two values. The requested time probably falls within a spring-forward gap of size DT. Follow the common practice in this case, which is to return a time that is DT away from the requested time, preferring a time whose - tm_isdst differs from the requested value. In practice, - this is more useful than returning -1. */ + tm_isdst differs from the requested value. (If no tm_isdst + was requested and only one of the two values has a nonzero + tm_isdst, prefer that value.) In practice, this is more + useful than returning -1. */ break; else if (--remaining_probes == 0) return -1; |