Skip to content
Tcl Source Code View Ticket
Login

View Ticket

clock scan error

Closed / Wont Fix2882209fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-10-20 08:38:51
% set start 1256421600
% clock format $start
Sun Oct 25 00:00:00 CEST 2009
% clock format [clock scan "[clock format $start] +24 hours"] 
Sun Oct 25 23:00:00 CET 2009
% clock format [clock scan "[clock format $start] +1 day"]
Sun Oct 25 23:00:00 CET 2009
% clock format [clock scan "[clock format $start] +2 day"] 
Mon Oct 26 23:00:00 CET 2009

The first clock scan command "could" be ok, but other results are wrong: at least one hour is missing (time switching from CEST to CET is probably the culprit).

the same thing but using [clock add] give good results.
dzolli Ticket [2882209fff]: 1 change [History diff]2009-10-20 15:44:57
dkf Ticket [2882209fff]: 1 change [History diff]2009-10-21 20:18:24
kennykbplain2009-10-29 07:40:20
This is an example of why [clock scan] without a '-format' is so very nasty.

When you do [clock format [clock scan "[clock format $start] + 1 day"]], what that winds up asking [clock scan] to parse is the string:

Sun Oct 25 23:00:00 CEST 2009 + 1 day

All goes well with parsing, and we get:

year 2009 month 10 day 25 time of day 00:00:00 + 1 day timezone CEST

Adjusting the date by 1 day gives

year 2009 month 10 day 26 time of day 00:00:00 timezone CEST

And - CEST is still in effect here- because it's specified explicitly as the timezone!
So even though the specified time is after the Summer Time->Standard Time conversion, it's interpreted in Summer Time and results in a time that's an hour off.

But if we try to fix this, it would break the case where we have an input string with a timezone other than the system timezone:

Sun Oct 25 00:00:00 EDT 2009

As I mentioned earlier, [clock add] will work.  If you need 8.4 compatibility, probably the best option is:

clock format [clock scan {+1 day} -base $start]

which also gets the right answer, and is shorter and simpler than what you've tried.

Also, using any format without a timezone in the inner [clock format] works.

% clock format [clock scan "+1 day" -base $start]
Mon Oct 26 00:00:00 CET 2009
% clock format [clock scan "[clock format $start -format {%Y-%m-%d %H:%M:%S}] +1 day"]
Mon Oct 26 00:00:00 CET 2009
kennykb Pending ticket [2882209fff]. [History diff]2009-10-29 07:40:26
sf-robotplain2009-11-12 09:20:22
allow_comments - 1

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Log in (anonymous is fine) to add a comment.