summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2005-11-30 15:39:37 (GMT)
committerKevin B Kenny <kennykb@acm.org>2005-11-30 15:39:37 (GMT)
commitcdd6051c36020fca89502380c47fe1369042135d (patch)
tree9682d7011acbc759ccbec85c525fffacbd213a87
parent0ffab670ecce5cacfba7a617cb3a30d8bd42c1d0 (diff)
downloadtcl-cdd6051c36020fca89502380c47fe1369042135d.zip
tcl-cdd6051c36020fca89502380c47fe1369042135d.tar.gz
tcl-cdd6051c36020fca89502380c47fe1369042135d.tar.bz2
fix [clock format -timezone :localtime] for times before the Posix Epoch
-rw-r--r--ChangeLog10
-rw-r--r--generic/tclClock.c13
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 <kennykb@acm.org>
- * 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 <kennykb@acm.org>
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;