Tcl Source Code

View Ticket
Login
EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA
Ticket UUID: 3475995
Title: [solved/opt] clock scan success by logical invalid date/time
Type: Bug Version: obsolete: 8.5.11
Submitter: sebres Created on: 2012-01-19 10:58:42
Subsystem: 06. Time Measurement Assigned To: aku
Priority: 4 Severity: Minor
Status: Open Last Modified: 2017-12-28 17:52:24
Resolution: None Closed By: nobody
    Closed on:
Description:
Behavior: After introducing tcl8.5 the scan does not fails on logical invalid dates like 02/30/2008 and build another date as specified :
% clock format [clock scan "2008-02-30"]
Sat Mar 01 00:00:00 CET 2008
% clock format [clock scan "24:62:80"] -format {%T}
23:59:59

Solution: see attached patch - patched execute :
% clock format [clock scan "2008-02-30"]
unable to convert date-time string "2008-02-30": invalid day
    while executing
"clock scan "2008-02-30""
% clock format [clock scan "24:62:80"] -format {%T}
unable to convert date-time string "24:62:80": invalid time
    while executing
"clock scan "24:62:80""

To call "clock scan" without validating use this one (backwards compatible to 8.5.11):
% clock format [clock scan "2008-02-30" -valid 0]
Sat Mar 01 00:00:00 CET 2008
% clock format [clock scan "24:62:80" -valid 0] -format {%T}
23:59:59

The patch contains more as only this fix - example ::tcl::clock::MakeDate - to create a seconds/date dict directly (but here without date validating - see below),
for example to create date from SQL-engine structures :
% puts [set date [::tcl::clock::MakeDate year 2008 month 2 dayOfMonth 20 hour 0 minute 0 second 0 tzName {}]]
year 2008 month 2 dayOfMonth 20 hour 0 minute 0 second 0 tzName {} era CE julianDay 2454517 secondOfDay 0 localSeconds 1203465600 seconds 1203462000
% puts "[dict get $date seconds] - [clock format [dict get $date seconds]]"
1203462000 - Wed Feb 20 00:00:00 CET 2008

To validate given date structure - use ::tcl::clock::ValidDate :
% puts [set date [::tcl::clock::MakeDate year 2008 month 2 dayOfMonth 20 hour 0 minute 0 second 0 tzName {}]]
year 2008 month 2 dayOfMonth 20 hour 0 minute 0 second 0 tzName {} era CE julianDay 2454517 secondOfDay 0 localSeconds 1203465600 seconds 1203462000
% ::tcl::clock::ValidDate $date {}
% puts [set date [::tcl::clock::MakeDate year 2008 month 2 dayOfMonth 32 hour 0 minute 0 second 0 tzName {}]]
year 2008 month 2 dayOfMonth 32 hour 0 minute 0 second 0 tzName {} era CE julianDay 2454529 secondOfDay 0 localSeconds 1204502400 seconds 1204498800
% ::tcl::clock::ValidDate $date {}
unable to convert date-time string "": invalid day
    while executing
"::tcl::clock::ValidDate $date {}"
User Comments: sebres added on 2017-12-28 17:52:24: (text/x-fossil-wiki)
Re-implemented in C for new clock-engine (tclclockmod), see <a href="https://github.com/sebres/tclclockmod/pull/10">github/sebres/tclclockmod#10</a>.

sebres added on 2012-02-15 17:47:28:
Dkf has fixed it in core-8-5-branch. Thanks.

So it's now safe within core-8-5-branch.

sebres added on 2012-02-15 00:09:53:
I have commited new version into
http://core.tcl.tk/tcl/info/aa30a04b13

currently not safe for current development core-8-5-branch (see Artifact 3487626)

safe for original tcl8.5

sebres added on 2012-02-02 16:26:14:

File Added - 434679: clock.tcl

sebres added on 2012-02-02 16:25:38:

File Added - 434678: clock.tcl.patch

sebres added on 2012-02-02 16:24:43:
In addition, i have made performance patch for clock.tcl (attached) ... with up to double performance increase.
Please do not forget that command "scan", compared to the standard version, also validate the date and time (i.e. additional time needed for Valid file), but nevertheless still faster in patched version.
To disable this (work as original tcl) use "-valid 0" arguments.

% set s [clock seconds]; puts [time {clock format $s} 50000]
38.76 microseconds per iteration
% set s [clock seconds]; puts [time {clock format $s -locale de} 50000]
40.3 microseconds per iteration
% set s [clock seconds]; puts [time {clock format $s -format %A%B/%d/%Y -locale en} 50000]
28.44 microseconds per iteration
% set s [clock seconds]; puts [time {clock format $s -format %A%B/%d/%Y -locale de} 50000]
29.06 microseconds per iteration
% set s [clock seconds]; puts [time {clock format $s -format %A%B/%d/%Y -locale fr} 50000]
29.06 microseconds per iteration
%
% puts [time {clock scan "10/10/2011"} 50000]
40.62 microseconds per iteration
% puts [time {clock scan "10/10/2011" -format %m/%d/%Y} 50000]
94.36 microseconds per iteration
% puts [time {clock scan "10/10/2011" -format %m/%d/%Y -locale de} 50000]
96.56 microseconds per iteration
% puts [time {clock scan "WednesdayJuly/29/1987" -format %A%B/%d/%Y -locale en} 50000]
159.7 microseconds per iteration
% puts [time {clock scan "MittwochJuli/29/1987" -format %A%B/%d/%Y -locale de} 50000]
216.88 microseconds per iteration
% puts [time {clock scan "mercredijuillet/29/1987" -format %A%B/%d/%Y -locale fr} 50000]
182.5 microseconds per iteration
%

% source {other/clock.tcl}
% tcl::clock::ClearCaches
%

% set s [clock seconds]; puts [time {clock format $s} 50000]
22.5 microseconds per iteration
% set s [clock seconds]; puts [time {clock format $s -locale de} 50000]
22.18 microseconds per iteration
% set s [clock seconds]; puts [time {clock format $s -format %A%B/%d/%Y -locale en} 50000]
18.44 microseconds per iteration
% set s [clock seconds]; puts [time {clock format $s -format %A%B/%d/%Y -locale de} 50000]
18.74 microseconds per iteration
% set s [clock seconds]; puts [time {clock format $s -format %A%B/%d/%Y -locale fr} 50000]
18.44 microseconds per iteration
%
% puts [time {clock scan "10/10/2011"} 50000]
36.56 microseconds per iteration
% puts [time {clock scan "10/10/2011" -format %m/%d/%Y} 50000]
60.62 microseconds per iteration
% puts [time {clock scan "10/10/2011" -format %m/%d/%Y -locale de} 50000]
62.5 microseconds per iteration
% puts [time {clock scan "WednesdayJuly/29/1987" -format %A%B/%d/%Y -locale en} 50000]
143.1 microseconds per iteration
% puts [time {clock scan "MittwochJuli/29/1987" -format %A%B/%d/%Y -locale de} 50000]
176.24 microseconds per iteration
% puts [time {clock scan "mercredijuillet/29/1987" -format %A%B/%d/%Y -locale fr} 50000]
147.8 microseconds per iteration

sebres added on 2012-01-19 17:58:42:

File Added - 433455: clock.tcl.patch

Attachments: