|
2024-07-16
| ||
| 18:26 | • Closed ticket [3ee8f1c2a7]: Clock scan issues with validation disabled. plus... artifact: 28d337b9ca user: sebres | |
| 17:42 | clock: fixed regression [3ee8f1c2a785f4d8]: time overflow (without validation) must cause day increm... check-in: 70997824b1 user: sebres tags: core-8-branch | |
| 16:24 | clock.test: more regression tests: clock-46.[56] cherry-picked from 8.7, clock-46.7 to illustrate re... check-in: a05ecc4f93 user: sebres tags: core-8-6-branch | |
| 15:37 | • Ticket [3ee8f1c2a7] Clock scan issues with validation disabled. status still... artifact: eb3b5c1d5f user: sebres | |
|
2024-07-15
| ||
| 10:39 | • Ticket [3ee8f1c2a7]: 4 changes artifact: 940aa28b96 user: oehhar | |
| 09:47 | • New ticket [3ee8f1c2a7]. artifact: 5085853c52 user: sbron | |
Clock scan issues with validation disabled.
In my code, I frequently use the following method to get the epoch time of the next midnight:
set midnight [clock scan 24:00:00 -format %T]
In Tcl 9.0 that currently throws an error. Apparently I need to use the option -validate 0 to allow the Tcl 8.6 behavior.
First of all, there is no mention of the -validate option in the clock manual page. TIP #688 claims that the default value for the -validate option is 0. In practice it seems to actually be 1.
However, the biggest problem is that the produced value is incorrect. Clearly 24:00:00 should be 1 second after 23:59:59. But that is not the case. I wrote the following test script:
if {[package vsatisfies [package present Tcl] 9]} {
set novalidate {-validate 0}
} else {
set novalidate {}
}
set sec1 [clock scan 23:59:59 -format %T {*}$novalidate]
set sec2 [clock scan 24:00:00 -format %T {*}$novalidate]
puts [expr {$sec2 - $sec1}]
In Tcl 8.6 this produces a result of 1, as expected. In Tcl 9.0 it reports -86400 (possibly depending on the day of the week the script is executed).
Thanks for the ticket, great! Just an annotation about the default value: TIP 690 changed the default value from 0 to 1: https://core.tcl-lang.org/tips/doc/trunk/tip/690.md
Take care, Harald
Although I personally would rather use something like:
clock scan "+1 day"
instead of
clock scan 24:00:00
it is indeed a certain regression (which was not covered previously in the test suite).
I'll add related tests to 8.6+ and fix it ASAP in 8.7+.
By the way, instead of -validate 0 arguments, one could use ::tcl::unsupported::clock::configure -validate 0 (previously clock configure -validate 0) to restore previous behaviour (surely only after the issue with not incremented date gets fixed).
Fixed in [70997824b1e313a7] (8.7) and [d15ae7fe510f3a7d] (9.0)...
Although, how one could see, it introduces now a small deviation to previous handling, this time in freescan (without -format argument), see test clock-46.6 - it doesn't return -1 anymore for invalid time (without validation) and behaves like "normal" scan now. It happens because of code deduplication in new clock engine - both scans convert the input time using ToSeconds function, which was modified now to fix this issue. And because freescan is legacy (deprecated) thing, I have no intention to hold it compatible to 8.6, moreover I'd like to keep both (scan and freescan) consistent to each other, so freescan behaves now more similar to scan (with format).