Module Name:    src
Committed By:   christos
Date:           Sun Oct 16 17:59:32 UTC 2011

Modified Files:
        src/lib/libc/time: Makefile ctime.3 localtime.c

Log Message:
Add code (not enabled) that allows mktime() to return a value for times
in the DST gap when tm_isdst == -1, like glibc does. Document both behaviors.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/time/Makefile
cvs rdiff -u -r1.42 -r1.43 src/lib/libc/time/ctime.3
cvs rdiff -u -r1.58 -r1.59 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/Makefile
diff -u src/lib/libc/time/Makefile:1.4 src/lib/libc/time/Makefile:1.5
--- src/lib/libc/time/Makefile:1.4	Sun Sep  4 06:10:26 2011
+++ src/lib/libc/time/Makefile	Sun Oct 16 13:59:32 2011
@@ -113,6 +113,8 @@ LDLIBS=
 #  -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1
 #	if you do not want run time warnings about formats that may cause
 #	year 2000 grief
+#  -DNO_ERROR_IN_DST_GAP=1
+#	if you want mktime() not to return an error in the DST gap.
 #  -DZIC_MAX_ABBR_LEN_WO_WARN=3
 #	(or some other number) to set the maximum time zone abbreviation length
 #	that zic will accept without a warning (the default is 6)

Index: src/lib/libc/time/ctime.3
diff -u src/lib/libc/time/ctime.3:1.42 src/lib/libc/time/ctime.3:1.43
--- src/lib/libc/time/ctime.3:1.42	Sat Jul  9 05:12:11 2011
+++ src/lib/libc/time/ctime.3	Sun Oct 16 13:59:32 2011
@@ -1,8 +1,8 @@
-.\" $NetBSD: ctime.3,v 1.42 2011/07/09 09:12:11 plunky Exp $
+.\" $NetBSD: ctime.3,v 1.43 2011/10/16 17:59:32 christos Exp $
 .\"
 .\" XXX: Lincense missing?
 .\"
-.Dd July 9, 2011
+.Dd October 16, 2011
 .Dt CTIME 3
 .Os
 .Sh NAME
@@ -245,6 +245,19 @@ are determined.
 The function returns the specified calendar time;
 if the calendar time cannot be represented, it returns
 .Va "(time_t)-1" .
+This can happen either because the resulting conversion would not fit
+in a
+.Vt time_t
+variable, or because the time specified happens to be in the daylight
+savings gap and
+.Fa tm_isdst
+was set to
+.Dv \-1 .
+Other
+.Fn mktime
+implementations do not return an error in the second case and return
+the appropriate time offset after the daylight savings gap.
+There is code to mimick this behavior, but it is not enabled by default.
 .It Fn mktime_z "tz" "tm"
 The
 .Fn mktime_z

Index: src/lib/libc/time/localtime.c
diff -u src/lib/libc/time/localtime.c:1.58 src/lib/libc/time/localtime.c:1.59
--- src/lib/libc/time/localtime.c:1.58	Sun Sep  4 06:10:26 2011
+++ src/lib/libc/time/localtime.c	Sun Oct 16 13:59:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: localtime.c,v 1.58 2011/09/04 10:10:26 christos Exp $	*/
+/*	$NetBSD: localtime.c,v 1.59 2011/10/16 17:59:32 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.58 2011/09/04 10:10:26 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.59 2011/10/16 17:59:32 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -1912,6 +1912,27 @@ time2sub(const timezone_t sp, struct tm 
 					return WRONG;
 				--hi;
 			}
+#ifdef NO_ERROR_IN_DST_GAP
+			if (lo - 1 == hi && yourtm.tm_isdst < 0) {
+				time_t off = 0;
+				for (i = sp->typecnt - 1; i >= 0; --i) {
+					for (j = sp->typecnt - 1; j >= 0; --j) {
+						if (sp->ttis[j].tt_isdst ==
+						    sp->ttis[i].tt_isdst)
+							continue;
+						off = sp->ttis[j].tt_gmtoff -
+						    sp->ttis[i].tt_gmtoff;
+						break;
+					}
+					if (j >= 0)
+						break;
+				}
+				if (off) {
+					t = hi + off;
+					break;
+				}
+			}
+#endif
 			if (lo > hi)
 				return WRONG;
 			if (dir > 0)

Reply via email to