sebres added on 2019-05-09 17:57:43:
And possibly still one case:
% puts [clock format [clock scan "01/01/1970 00:00:00" -timezone "+0530"] -gmt 1 -locale en]
Wed Dec 31 18:30:00 GMT 1969
% puts [clock format [clock scan "01/01/1970 00:00:00" -timezone "GMT+05:30"] -gmt 1 -locale en]
Thu Jan 01 05:30:00 GMT 1970
# ------------------------------
% puts [clock format [clock scan "01/01/1970 00:00:00" -timezone "+05"] -gmt 1 -locale en]
Wed Dec 31 19:00:00 GMT 1969
% puts [clock format [clock scan "01/01/1970 00:00:00" -timezone "GMT+05"] -gmt 1 -locale en]
Thu Jan 01 05:00:00 GMT 1970
% puts [clock format [clock scan "01/01/1970 00:00:00" -timezone "GMT+5"] -gmt 1 -locale en]
Thu Jan 01 05:00:00 GMT 1970
# ------------------------------
% puts [clock format 0 -timezone +05 -locale en]
Thu Jan 01 05:00:00 +05 1970
% puts [clock format 0 -timezone GMT+05 -locale en]
Wed Dec 31 19:00:00 GMT 1969
% puts [clock format 0 -timezone GMT+05:00 -locale en]
Wed Dec 31 19:00:00 GMT 1969
Something tells me that the TZ are the same (e. g. +05:00 is GMT+05:00) so it should produce the same results.
And because forwards (format) and backwards (scan) conversions are affected equally, it looks like the loading of the TZ is affected, and red marked are result of invalid sign by the applying of offset of the wrong time zone (prefixed with GMT).
sebres added on 2019-05-02 19:18:26:
More tests showing additionally another basic difference between both scan proceedings - fixed-format scan is following the general rule "if the string contains neither a %s format group nor a group specifying the hour of the day, then midnight (00:00, the start of the given date) is used." as it is documented, where free scan is always preferring a current time in this case.
Here is a short script illustrating this difference related to the time zone issue (so free scan is also wrong here if another TZ used in the input):
foreach tz {"GMT" "CET" "CEST" "CST" "CDT" "EST" "EDT"} {
foreach s {
{clock scan $tz -format %Z -base 100000000 -gmt 1}
{clock scan $tz -base 100000000 -gmt 1}
} {
puts "% [format %-55s [subst $s]] ==> [format %10s [set c [if 1 $s]]], [catch {clock format $c -timezone $tz -locale en} r; set r]"
}
}
puts --------------------------
foreach tz {"GMT" "CET" "EST"} {
foreach s {
{clock scan "" -format "" -base 100000000 -timezone $tz}
{clock scan "" -base 100000000 -timezone $tz}
} {
puts "% [format %-55s [subst $s]] ==> [format %10s [set c [if 1 $s]]], [catch {clock format $c -timezone $tz -locale en} r; set r]"
}
}
Original (unpatched tcl-clock):
% clock scan GMT -format %Z -base 100000000 -gmt 1 ==> 99964800, Sat Mar 03 00:00:00 GMT 1973
% clock scan GMT -base 100000000 -gmt 1 ==> 100000000, Sat Mar 03 09:46:40 GMT 1973
% clock scan CET -format %Z -base 100000000 -gmt 1 ==> 99961200, Sat Mar 03 00:00:00 CET 1973
% clock scan CET -base 100000000 -gmt 1 ==> 99996400, Sat Mar 03 09:46:40 CET 1973
% clock scan CEST -format %Z -base 100000000 -gmt 1 ==> 99957600, time zone CEST not found
% clock scan CEST -base 100000000 -gmt 1 ==> 99992800, time zone CEST not found
% clock scan CST -format %Z -base 100000000 -gmt 1 ==> 99986400, time zone CST not found
% clock scan CST -base 100000000 -gmt 1 ==> 100021600, time zone CST not found
% clock scan CDT -format %Z -base 100000000 -gmt 1 ==> 99982800, time zone CDT not found
% clock scan CDT -base 100000000 -gmt 1 ==> 100018000, time zone CDT not found
% clock scan EST -format %Z -base 100000000 -gmt 1 ==> 99982800, Sat Mar 03 00:00:00 EST 1973
% clock scan EST -base 100000000 -gmt 1 ==> 100018000, Sat Mar 03 09:46:40 EST 1973
% clock scan EDT -format %Z -base 100000000 -gmt 1 ==> 99979200, time zone EDT not found
% clock scan EDT -base 100000000 -gmt 1 ==> 100014400, time zone EDT not found
--------------------------
% clock scan "" -format "" -base 100000000 -timezone GMT ==> 99964800, Sat Mar 03 00:00:00 GMT 1973
% clock scan "" -base 100000000 -timezone GMT ==> 100000000, Sat Mar 03 09:46:40 GMT 1973
% clock scan "" -format "" -base 100000000 -timezone CET ==> 99961200, Sat Mar 03 00:00:00 CET 1973
% clock scan "" -base 100000000 -timezone CET ==> 100000000, Sat Mar 03 10:46:40 CET 1973
% clock scan "" -format "" -base 100000000 -timezone EST ==> 99982800, Sat Mar 03 00:00:00 EST 1973
% clock scan "" -base 100000000 -timezone EST ==> 100000000, Sat Mar 03 04:46:40 EST 1973
The fix changes the behavior, considering the higher precedence of TZ in input, as well as the general rule (no time == 00:00) of the fixed-format scan and free scan (no time == time of now):
% clock scan GMT -format %Z -base 100000000 -gmt 1 ==> 99964800, Sat Mar 03 00:00:00 GMT 1973
% clock scan GMT -base 100000000 -gmt 1 ==> 100000000, Sat Mar 03 09:46:40 GMT 1973
% clock scan CET -format %Z -base 100000000 -gmt 1 ==> 99961200, Sat Mar 03 00:00:00 CET 1973
% clock scan CET -base 100000000 -gmt 1 ==> 100000000, Sat Mar 03 10:46:40 CET 1973
% clock scan CEST -format %Z -base 100000000 -gmt 1 ==> 99957600, Sat Mar 03 00:00:00 +0200 1973
% clock scan CEST -base 100000000 -gmt 1 ==> 100000000, Sat Mar 03 11:46:40 +0200 1973
% clock scan CST -format %Z -base 100000000 -gmt 1 ==> 99986400, Sat Mar 03 00:00:00 -0600 1973
% clock scan CST -base 100000000 -gmt 1 ==> 100000000, Sat Mar 03 03:46:40 -0600 1973
% clock scan CDT -format %Z -base 100000000 -gmt 1 ==> 99982800, Sat Mar 03 00:00:00 -0500 1973
% clock scan CDT -base 100000000 -gmt 1 ==> 100000000, Sat Mar 03 04:46:40 -0500 1973
% clock scan EST -format %Z -base 100000000 -gmt 1 ==> 99982800, Sat Mar 03 00:00:00 EST 1973
% clock scan EST -base 100000000 -gmt 1 ==> 100000000, Sat Mar 03 04:46:40 EST 1973
% clock scan EDT -format %Z -base 100000000 -gmt 1 ==> 99979200, Sat Mar 03 00:00:00 -0400 1973
% clock scan EDT -base 100000000 -gmt 1 ==> 100000000, Sat Mar 03 05:46:40 -0400 1973
--------------------------
% clock scan "" -format "" -base 100000000 -timezone GMT ==> 99964800, Sat Mar 03 00:00:00 GMT 1973
% clock scan "" -base 100000000 -timezone GMT ==> 100000000, Sat Mar 03 09:46:40 GMT 1973
% clock scan "" -format "" -base 100000000 -timezone CET ==> 99961200, Sat Mar 03 00:00:00 CET 1973
% clock scan "" -base 100000000 -timezone CET ==> 100000000, Sat Mar 03 10:46:40 CET 1973
% clock scan "" -format "" -base 100000000 -timezone EST ==> 99982800, Sat Mar 03 00:00:00 EST 1973
% clock scan "" -base 100000000 -timezone EST ==> 100000000, Sat Mar 03 04:46:40 EST 1973
sebres added on 2019-05-01 16:05:15:
Following snippet illustrates the ambiguity problem:
The time-point of the applying of time zone if only time is provided for scan
of if some info is missing and will be retrieved from base.
Rather it looks like a precedence question - which time zone should win:
- - either the default (or specified as argument) (Variant 1)
- - or specified in the input string (Variant 2)
proc _test {base args} {
foreach defTZ {:GMT :America/New_York} {
set trgTZ [lindex $args 0 end]
puts "== $defTZ =="
puts "base:\t[clock format $base -timezone $defTZ -locale en]\t = [clock format $base -timezone $trgTZ -locale en]"
set time [clock scan {*}$args -timezone $defTZ -base $base]
puts "scan:\t[clock format $time -timezone $defTZ -locale en]\t = [clock format $time -timezone $trgTZ -locale en]"
}
}
Variant 1:
scan assumes retrieving date of base using default TZ (or given as argument),
this is the current behaviour of free-scan in tcl-core
% _test 1556240400 {10:00 GMT} -format {%H:%M %Z}
== :GMT ==
base: Fri Apr 26 01:00:00 GMT 2019 = Fri Apr 26 01:00:00 GMT 2019
scan: Fri Apr 26 10:00:00 GMT 2019 = Fri Apr 26 10:00:00 GMT 2019
== :America/New_York ==
base: Thu Apr 25 21:00:00 EDT 2019 = Fri Apr 26 01:00:00 GMT 2019
scan: Thu Apr 25 06:00:00 EDT 2019 = Thu Apr 25 10:00:00 GMT 2019
Variant 2:
scan assumes retrieving date of base using TZ from the input after time,
this is the current behaviour of format-scan in tcl-core
% _test 1556240400 {10:00 GMT} -format {%H:%M %Z}
== :GMT ==
base: Fri Apr 26 01:00:00 GMT 2019 = Fri Apr 26 01:00:00 GMT 2019
scan: Fri Apr 26 10:00:00 GMT 2019 = Fri Apr 26 10:00:00 GMT 2019
== :America/New_York ==
base: Thu Apr 25 21:00:00 EDT 2019 = Fri Apr 26 01:00:00 GMT 2019
scan: Fri Apr 26 06:00:00 EDT 2019 = Fri Apr 26 10:00:00 GMT 2019
My tclclockmod (and clock-speedup branch) uses Variant 1 at the moment:
the missing input-parts are converted from base relative to default/argument time zone,
so it has precedence over the time zone specified in input (which is then applied only to the time resp. values of the input string).
And current (broken) state of tcl-core (in all versions):
format-scan and free-scan working differently (and this is uncovered in test-suite at the moment).
Here is the result as diff:
-% _test 1556240400 {10:00 GMT} -format {%H:%M %Z}; # format scan
+% _test 1556240400 {10:00 GMT} ; # free scan
== :GMT ==
base: Fri Apr 26 01:00:00 GMT 2019 = Fri Apr 26 01:00:00 GMT 2019
scan: Fri Apr 26 10:00:00 GMT 2019 = Fri Apr 26 10:00:00 GMT 2019
== :America/New_York ==
base: Thu Apr 25 21:00:00 EDT 2019 = Fri Apr 26 01:00:00 GMT 2019
-scan: Fri Apr 26 06:00:00 EDT 2019 = Fri Apr 26 10:00:00 GMT 2019
+scan: Thu Apr 25 06:00:00 EDT 2019 = Thu Apr 25 10:00:00 GMT 2019
|