From: SourceForge.net <no...@so...> - 2012-02-02 09:24:45
|
Bugs item #3475995, was opened at 2012-01-19 02:58 Message generated for change (Settings changed) made by sebres You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=110894&aid=3475995&group_id=10894 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: 06. Time Measurement Group: current: 8.5.11 Status: Open Resolution: None >Priority: 4 Private: No Submitted By: sebres (sebres) Assigned to: Kevin B KENNY (kennykb) >Summary: [solved/opt] clock scan success by logical invalid date/time Initial Comment: 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 {}" ---------------------------------------------------------------------- >Comment By: sebres (sebres) Date: 2012-02-02 01:24 Message: 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 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=110894&aid=3475995&group_id=10894 |