Module Name: src
Committed By: riz
Date: Fri Feb 8 20:30:43 UTC 2013
Modified Files:
src/lib/libutil [netbsd-6-0]: parsedate.y
Log Message:
Pull up following revision(s) (requested by apb in ticket #791):
lib/libutil/parsedate.y: revision 1.13
mktime(3) works in local time, and trying to trick it by
setting tm_gmtoff doesn't work. Instead, call mktime_z(3)
with a null timezone (so it works in UTC) and adjust the
result afterwards. Now "date -d @0" correctly
prints the local equivalent of 1970-01-01 00:00:00 UTC.
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.11.8.1 src/lib/libutil/parsedate.y
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.11 src/lib/libutil/parsedate.y:1.11.8.1
--- src/lib/libutil/parsedate.y:1.11 Sat Dec 17 19:14:10 2011
+++ src/lib/libutil/parsedate.y Fri Feb 8 20:30:43 2013
@@ -590,7 +590,8 @@ Convert(
DSTMODE DSTmode /* DST on/off/maybe */
)
{
- struct tm tm;
+ struct tm tm = {.tm_sec = 0};
+ time_t result;
/* XXX Y2K */
if (Year < 0)
@@ -611,9 +612,11 @@ Convert(
case DSToff: tm.tm_isdst = 0; break;
default: tm.tm_isdst = -1; break;
}
- tm.tm_gmtoff = -Timezone;
- return mktime(&tm);
+ /* We rely on mktime_z(NULL, ...) working in UTC, not in local time. */
+ result = mktime_z(NULL, &tm);
+ result -= Timezone;
+ return result;
}