summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'time.c')
-rw-r--r--time.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/time.c b/time.c
index 8e79080380..dd3b6eb666 100644
--- a/time.c
+++ b/time.c
@@ -328,8 +328,6 @@ make_time_t(tptr, utc_p)
guess += (tptr->tm_sec - tm->tm_sec);
#ifndef NEGATIVE_TIME_T
if (guess < 0) goto out_of_range;
-#else
- if (oguess > 365 * 24 * 3600 && guess < 0) goto out_of_range;
#endif
if (!utc_p) { /* localtime zone adjust */
@@ -362,17 +360,32 @@ make_time_t(tptr, utc_p)
tm = localtime(&guess);
if (!tm) goto error;
if (lt.tm_isdst != tm->tm_isdst || tptr->tm_hour != tm->tm_hour) {
- oguess = guess - 3600;
- tm = localtime(&oguess);
+ time_t tmp = guess - 3600;
+ tm = localtime(&tmp);
if (!tm) goto error;
if (tptr->tm_hour == tm->tm_hour) {
- guess = oguess;
+ guess = tmp;
+ }
+ else if (lt.tm_isdst == tm->tm_isdst) {
+ tmp = guess + 3600;
+ tm = localtime(&tmp);
+ if (!tm) goto error;
+ if (tptr->tm_hour == tm->tm_hour) {
+ guess = tmp;
+ }
}
}
+ if (tptr->tm_min != tm->tm_min) {
+ guess += (tptr->tm_min - tm->tm_min) * 60;
+ }
#ifndef NEGATIVE_TIME_T
if (guess < 0) goto out_of_range;
#endif
}
+#ifdef NEGATIVE_TIME_T
+ if (oguess > 365 * 24 * 3600 && guess < 0) goto out_of_range;
+ if (guess > 365 * 24 * 3600 && oguess < 0) goto out_of_range;
+#endif
return guess;