summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--generic/tclClock.c10
-rw-r--r--library/clock.tcl57
-rw-r--r--tests/clock.test15
4 files changed, 72 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 822da12..b95a8ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-08-12 Kevin Kenny <kennykb@acm.org>
+
+ * generic/tclClock.c (MktimeObjCmd):
+ * library/clock.tcl (GetSystemTimeZone, LoadZoneinfoFile,
+ ReadZoneinfoFile):
+ * tests/clock.test (clock-50.1):
+ Added functionality to read /etc/localtime if it exists, so that
+ Tcl's time can track system time on Linux even if TZ is not set.
+ Changed ::tcl::clock::Mktime to check for failure, and added a
+ test case that mimics failure but is really success.
+
2004-08-11 Kevin Kenny <kennykb@acm.org>
* generic/tclEvent.c: Eliminated the USE_THREAD_STORAGE
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 47f1e74..9134ab4 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.39 2005/08/09 13:31:27 dkf Exp $
+ * RCS: @(#) $Id: tclClock.c,v 1.40 2005/08/12 23:55:28 kennykb Exp $
*/
#include "tclInt.h"
@@ -319,8 +319,8 @@ TclClockMktimeObjCmd( ClientData clientData,
}
toConvert.tm_sec = i;
toConvert.tm_isdst = -1;
- toConvert.tm_wday = 0;
- toConvert.tm_yday = 0;
+ toConvert.tm_wday = -1;
+ toConvert.tm_yday = -1;
/* Convert the time. It is rumored that mktime is not thread
* safe on some platforms. */
@@ -334,7 +334,9 @@ TclClockMktimeObjCmd( ClientData clientData,
/* Return the converted time, or an error if conversion fails */
- if ( localErrno != 0 ) {
+ if ( localErrno != 0
+ || ( convertedTime == -1
+ && toConvert.tm_yday == -1 ) ) {
Tcl_SetObjResult
( interp,
Tcl_NewStringObj( "time value too large/small to represent",
diff --git a/library/clock.tcl b/library/clock.tcl
index 5ff786f..ccc55fd 100644
--- a/library/clock.tcl
+++ b/library/clock.tcl
@@ -13,7 +13,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: clock.tcl,v 1.17 2005/07/15 22:32:24 kennykb Exp $
+# RCS: @(#) $Id: clock.tcl,v 1.18 2005/08/12 23:55:28 kennykb Exp $
#
#----------------------------------------------------------------------
@@ -2926,18 +2926,18 @@ proc ::tcl::clock::GetSystemTimeZone {} {
set timezone $result
} elseif { ![catch {getenv TZ} result] } {
set timezone $result
+ } elseif { [info exists CachedSystemTimeZone] } {
+ set timezone $CachedSystemTimeZone
+ } elseif { $::tcl_platform(platform) eq {windows} } {
+ set timezone [GuessWindowsTimeZone]
+ } elseif { [file exists /etc/localtime]
+ && ![catch {ReadZoneinfoFile \
+ Tcl/Localtime /etc/localtime}] } {
+ set timezone :Tcl/Localtime
} else {
- if { [info exists CachedSystemTimeZone] } {
- set timezone $CachedSystemTimeZone
- } else {
- if { $::tcl_platform(platform) eq {windows} } {
- set timezone [GuessWindowsTimeZone]
- } else {
- set timezone :localtime
- }
- set CachedSystemTimeZone $timezone
- }
+ set timezone :localtime
}
+ set CachedSystemTimeZone $timezone
if { ![dict exists $TimeZoneBad $timezone] } {
dict set TimeZoneBad $timezone [catch {SetupTimeZone $timezone}]
}
@@ -3314,7 +3314,7 @@ proc ::tcl::clock::SetupTimeZone { timezone } {
# again with a time zone file - this time without a colon
if { [catch { LoadTimeZoneFile $timezone }]
- && [catch { LoadZoneinfoFile $timezone } - opts] } {
+ && [catch { ZoneinfoFile $timezone } - opts] } {
dict unset opts -errorinfo
return -options $opts "time zone $timezone not found"
}
@@ -3525,7 +3525,7 @@ proc ::tcl::clock::LoadTimeZoneFile { fileName } {
# Loads a binary time zone information file in Olson format.
#
# Parameters:
-# fileName - Path name of the file to load.
+# fileName - Relative path name of the file to load.
#
# Results:
# Returns an empty result normally; returns an error if no
@@ -3538,8 +3538,6 @@ proc ::tcl::clock::LoadTimeZoneFile { fileName } {
proc ::tcl::clock::LoadZoneinfoFile { fileName } {
- variable MINWIDE
- variable TZData
variable ZoneinfoPaths
# Since an unsafe interp uses the [clock] command in the master,
@@ -3558,6 +3556,33 @@ proc ::tcl::clock::LoadZoneinfoFile { fileName } {
}
unset fname
}
+ ReadZoneinfoFile $fileName $fname
+}
+
+#----------------------------------------------------------------------
+#
+# LoadZoneinfoFile --
+#
+# Loads a binary time zone information file in Olson format.
+#
+# Parameters:
+# fileName - Name of the time zone (relative path name of the
+# file).
+# fname - Absolute path name of the file.
+#
+# Results:
+# Returns an empty result normally; returns an error if no
+# Olson file was found or the file was malformed in some way.
+#
+# Side effects:
+# TZData(:fileName) contains the time zone data
+#
+#----------------------------------------------------------------------
+
+
+proc ReadZoneinfoFile {fileName fname} {
+ variable MINWIDE
+ variable TZData
if { ![info exists fname] } {
return -code error "$fileName not found"
}
@@ -3643,7 +3668,7 @@ proc ::tcl::clock::LoadZoneinfoFile { fileName } {
}
set TZData(:$fileName) $r
-
+ return
}
#----------------------------------------------------------------------
diff --git a/tests/clock.test b/tests/clock.test
index b8c864d..3ad928e 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -11,7 +11,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: clock.test,v 1.56 2005/07/15 22:32:24 kennykb Exp $
+# RCS: @(#) $Id: clock.test,v 1.57 2005/08/12 23:55:28 kennykb Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
@@ -35465,6 +35465,19 @@ test clock-49.2 {regression test - missing time zone file (Bug 1237907)} \
} \
-result {<-0500>+05:00:00<-0400>+04:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00 { 7:00:00 PM -0500} 1969}
+test clock-50.1 {format / scan -1 as a local time} {
+ if {[catch {
+ clock scan \
+ [clock format -1 -format %Y%m%d%H%M%S -timezone :localtime] \
+ -format %Y%m%d%H%M%S -timezone :localtime
+ } result]} {
+ if { [regexp "clock value too" $result] } {
+ set result -1
+ }
+ }
+ set result
+} -1
+
# cleanup
namespace delete ::testClock