summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormax <max@tclers.tk>2011-10-18 13:08:55 (GMT)
committermax <max@tclers.tk>2011-10-18 13:08:55 (GMT)
commitab5335a4c951b478bbedd4f5561b8a314da5b074 (patch)
treec0623b24025764f3cd3a377e5e33de81d5ccf90b
parent17f82d2daf4b9ae646c39c2922e7d73a7671ed05 (diff)
downloadtcl-ab5335a4c951b478bbedd4f5561b8a314da5b074.zip
tcl-ab5335a4c951b478bbedd4f5561b8a314da5b074.tar.gz
tcl-ab5335a4c951b478bbedd4f5561b8a314da5b074.tar.bz2
Don't cache the system timezone when it was derived from TCL_TZ or TZ.
-rw-r--r--ChangeLog7
-rw-r--r--library/clock.tcl27
-rw-r--r--tests/clock.test33
3 files changed, 56 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index d219048..5cf8570 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-10-18 Reinhard Max <max@suse.de>
+
+ * library/clock.tcl (::tcl::clock::GetSystemTimeZone): Cache the
+ time zone only if it was detected by one of the expensive
+ methods. Otherwise after unsetting TCL_TZ or TZ the previous value
+ will still be used.
+
2011-10-15 Venkat Iyer <venkat@comit.com>
* library/tzdata/America/Sitka : Update to Olson's tzdata2011l
* library/tzdata/Pacific/Fiji
diff --git a/library/clock.tcl b/library/clock.tcl
index b6ff359..2a4c7bd 100644
--- a/library/clock.tcl
+++ b/library/clock.tcl
@@ -3012,18 +3012,23 @@ proc ::tcl::clock::GetSystemTimeZone {} {
set timezone $result
} elseif {[set result [getenv TZ]] ne {}} {
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 {
- set timezone :localtime
}
- set CachedSystemTimeZone $timezone
+ if {![info exists timezone]} {
+ # Cache the time zone only if it was detected by one of the
+ # expensive methods.
+ if { [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 {
+ set timezone :localtime
+ }
+ set CachedSystemTimeZone $timezone
+ }
if { ![dict exists $TimeZoneBad $timezone] } {
dict set TimeZoneBad $timezone [catch {SetupTimeZone $timezone}]
}
diff --git a/tests/clock.test b/tests/clock.test
index 8c31f83..bda5e76 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -35895,6 +35895,39 @@ test clock-38.1 {regression - convertUTCToLocalViaC - east of Greenwich} \
} \
-result {01:00:00}
+test clock-38.2 {make sure TZ is not cached after unset} \
+ -setup {
+ if { [info exists env(TZ)] } {
+ set oldTZ $env(TZ)
+ unset env(TZ)
+ }
+ if { [info exists env(TCL_TZ)] } {
+ set oldTCLTZ $env(TCL_TZ)
+ unset env(TCL_TZ)
+ }
+ } \
+ -body {
+ set t1 [clock format 0]
+ # a time zone that is unlikely to anywhere
+ set env(TZ) "+04:20"
+ set t2 [clock format 0]
+ unset env(TZ)
+ set t3 [clock format 0]
+ expr {$t1 eq $t3 && $t1 ne $t2}
+ } \
+ -cleanup {
+ if { [info exists oldTZ] } {
+ set env(TZ) $oldTZ
+ unset oldTZ
+ }
+ if { [info exists oldTclTZ] } {
+ set env(TCL_TZ) $oldTclTZ
+ unset oldTclTZ
+ }
+ } \
+ -result 1
+
+
test clock-39.1 {regression - synonym timezones} {
clock format 0 -format {%H:%M:%S} -timezone :US/Eastern
} {19:00:00}