From cdd6051c36020fca89502380c47fe1369042135d Mon Sep 17 00:00:00 2001 From: Kevin B Kenny Date: Wed, 30 Nov 2005 15:39:37 +0000 Subject: fix [clock format -timezone :localtime] for times before the Posix Epoch --- ChangeLog | 10 ++++++---- generic/tclClock.c | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9cd8c74..d0b971d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,10 +20,12 @@ 2005-11-30 Kevin Kenny - * generic/tclClock.c: Fixed a bad refcount in previous commit that led - to a corrupted heap. Thanks to Miguel Sofer for pointing out this - bug. Also silenced a warning that some compilers gave about the - excessively long constant for JULIAN_SEC_POSIX_EPOCH. + * generic/tclClock.c: Fixed a bad refcount in previous commit that + led to a corrupted heap. Also silenced a warning that some + compilers gave about the excessively long constant for + JULIAN_SEC_POSIX_EPOCH. Also fixed a bug where [clock format] + would fail in the :localtime zone for times before the Posix + Epoch. Thanks to Miguel Sofer for pointing out all of these. 2005-11-29 Kevin Kenny diff --git a/generic/tclClock.c b/generic/tclClock.c index 891ea25..340a06c 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclClock.c,v 1.45 2005/11/30 15:09:41 kennykb Exp $ + * RCS: @(#) $Id: tclClock.c,v 1.46 2005/11/30 15:39:37 kennykb Exp $ */ #include "tclInt.h" @@ -575,6 +575,7 @@ ConvertLocalToUTCUsingC( ) { struct tm timeVal; int localErrno; + int secondOfDay; /* Convert the given time to a date */ @@ -588,9 +589,13 @@ ConvertLocalToUTCUsingC( timeVal.tm_year = fields->year - 1900; timeVal.tm_mon = fields->month - 1; timeVal.tm_mday = fields->dayOfMonth; - timeVal.tm_hour = (int)((fields->localSeconds / 3600) % 24); - timeVal.tm_min = (int)((fields->localSeconds / 60) % 60); - timeVal.tm_sec = (int)(fields->localSeconds % 60); + secondOfDay = (int)(fields->localSeconds % SECONDS_PER_DAY); + if (secondOfDay < 0) { + secondOfDay += SECONDS_PER_DAY; + } + timeVal.tm_hour = (secondOfDay / 3600) % 24; + timeVal.tm_min = (secondOfDay / 60) % 60; + timeVal.tm_sec = secondOfDay % 60; timeVal.tm_isdst = -1; timeVal.tm_wday = -1; timeVal.tm_yday = -1; -- cgit v0.12