Skip to content

Commit b15c0cb

Browse files
committed
more tests to cover issue [5137b4387019d0e1] - ensure cache of base is correct for :localtime (system TZ) if TZ-env changing (if there is no registry)
1 parent 18fa6f6 commit b15c0cb

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/clock.test

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36946,6 +36946,55 @@ test clock-38.3fm {ensure cache of base is correct for :localtime if TZ-env chan
3694636946
} \
3694736947
-result {{1970-01-02T07:30:00 +1130} {1970-01-02T03:30:00 +0730} {1970-01-01T23:30:00 +0330} {1970-01-01T20:00:00 +0000}}
3694836948

36949+
test clock-38.4sc {ensure cache of base is correct for :localtime if TZ-env changing / scan (system TZ, no registry)} \
36950+
-setup {
36951+
::testClock::_setupRegistry
36952+
# simulate we have no registry, so system TZ and :localtime get +HHMM format
36953+
proc ::tcl::clock::_hasRegistry {} {return 0}
36954+
} -body {
36955+
# force epoch switch and set first TZ (a time zone that is unlikely to anywhere) and use :localtime
36956+
set env(TZ) "+03:20"
36957+
clock scan "12:00:00" -format "%H:%M:%S" -base [expr {20*60*60}] -timezone :localtime -locale en
36958+
# force epoch switch, with unset TZ, it shall be system timezone now
36959+
unset -nocomplain env(TZ)
36960+
set t1 [clock scan "12:00:00" -format "%H:%M:%S" -base [expr {20*60*60}] -locale en]
36961+
# force epoch switch and set another TZ (a time zone that is unlikely to anywhere) and use system timezone
36962+
set env(TZ) "+04:20"
36963+
set t2 [clock scan "12:00:00" -format "%H:%M:%S" -base [expr {20*60*60}] -locale en]
36964+
# force epoch switch, with unset TZ, it shall be again system timezone
36965+
unset -nocomplain env(TZ)
36966+
set t3 [clock scan "12:00:00" -format "%H:%M:%S" -base [expr {20*60*60}] -locale en]
36967+
# compare scanned values (t1 must be equal t3 and not equal t2):
36968+
list [expr {$t1 == $t3 && $t1 != $t2}] [subst {$t1 == $t3 && $t1 != $t2}]
36969+
} -cleanup {
36970+
unset -nocomplain env(TZ)
36971+
::testClock::_cleanupRegistry
36972+
} -match glob -result {1 *}
36973+
test clock-38.4fm {ensure cache of base is correct for :localtime if TZ-env changing / format (system TZ, no registry)} \
36974+
-setup {
36975+
::testClock::_setupRegistry
36976+
# simulate we have no registry, so system TZ and :localtime get +HHMM format
36977+
proc ::tcl::clock::_hasRegistry {} {return 0}
36978+
} -body {
36979+
# force epoch switch and set first TZ (a time zone that is unlikely to anywhere) and use :localtime
36980+
set env(TZ) "+03:20"
36981+
clock format 0 -timezone :localtime -locale en
36982+
# force epoch switch, with unset TZ, it shall be system timezone now
36983+
unset -nocomplain env(TZ)
36984+
set t1 [clock format 0 -locale en]
36985+
# force epoch switch and set another TZ (a time zone that is unlikely to anywhere) and use system timezone
36986+
set env(TZ) "+04:20"
36987+
set t2 [clock format 0 -locale en]
36988+
# force epoch switch, with unset TZ, it shall be again system timezone
36989+
unset -nocomplain env(TZ)
36990+
set t3 [clock format 0 -locale en]
36991+
# compare formatted values (t1 must be equal t3 and not equal t2):
36992+
list [expr {$t1 eq $t3 && $t1 ne $t2}] [subst {"$t1" eq "$t3" && "$t1" ne "$t2"}]
36993+
} -cleanup {
36994+
unset -nocomplain env(TZ)
36995+
::testClock::_cleanupRegistry
36996+
} -match glob -result {1 *}
36997+
3694936998
test clock-39.1 {regression - synonym timezones} {
3695036999
clock format 0 -format {%H:%M:%S} -timezone :US/Eastern
3695137000
} {19:00:00}

0 commit comments

Comments
 (0)