Module Name:    src
Committed By:   christos
Date:           Tue Nov  8 18:37:32 UTC 2011

Modified Files:
        src/lib/libc/time: localtime.c

Log Message:
Change the way that we compute the time when we fall in the dst gap: instead
of supplying just the high bound and thus losing minutes and seconds, add
the DST offset to the struct tm (since we know we are going to move ahead
since we fell in the gap), and try again.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/libc/time/localtime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/time/localtime.c
diff -u src/lib/libc/time/localtime.c:1.63 src/lib/libc/time/localtime.c:1.64
--- src/lib/libc/time/localtime.c:1.63	Mon Nov  7 14:42:03 2011
+++ src/lib/libc/time/localtime.c	Tue Nov  8 13:37:31 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: localtime.c,v 1.63 2011/11/07 19:42:03 christos Exp $	*/
+/*	$NetBSD: localtime.c,v 1.64 2011/11/08 18:37:31 christos Exp $	*/
 
 /*
 ** This file is in the public domain, so clarified as of
@@ -10,7 +10,7 @@
 #if 0
 static char	elsieid[] = "@(#)localtime.c	8.17";
 #else
-__RCSID("$NetBSD: localtime.c,v 1.63 2011/11/07 19:42:03 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.64 2011/11/08 18:37:31 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -1802,6 +1802,9 @@ time2sub(const timezone_t sp, struct tm 
 
 	*okayp = FALSE;
 	yourtm = *tmp;
+#ifdef NO_ERROR_IN_DST_GAP
+again:
+#endif
 	if (do_norm_secs) {
 		if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec,
 		    SECSPERMIN))
@@ -1919,23 +1922,20 @@ time2sub(const timezone_t sp, struct tm 
 				--hi;
 			}
 #ifdef NO_ERROR_IN_DST_GAP
-			if (ilo != lo && lo - 1 == hi && yourtm.tm_isdst < 0) {
-				time_t off = 0;
+			if (ilo != lo && lo - 1 == hi && yourtm.tm_isdst < 0 &&
+			    do_norm_secs) {
 				for (i = sp->typecnt - 1; i >= 0; --i) {
 					for (j = sp->typecnt - 1; j >= 0; --j) {
+						time_t off;
 						if (sp->ttis[j].tt_isdst ==
 						    sp->ttis[i].tt_isdst)
 							continue;
 						off = sp->ttis[j].tt_gmtoff -
 						    sp->ttis[i].tt_gmtoff;
-						break;
+						yourtm.tm_sec += off < 0 ?
+						    -off : off;
+						goto again;
 					}
-					if (j >= 0)
-						break;
-				}
-				if (off) {
-					t = hi;
-					break;
 				}
 			}
 #endif

Reply via email to