Version 15 of clock scan

Updated 2013-02-11 18:48:19 by TCV

Part of the clock command. See http://purl.org/tcl/home/man/tcl8.5/TclCmd/clock.htm for the formal man page.

clock scan inputString ?-option value...?

Parses the time described in inputString and returns the number of seconds (since the start of the Unix epoch) that that time corresponds to. Supported -options are:

-base time
-format format
-gmt boolean
-locale localeName
-timezone zoneName

JMN 2007-11-14

On FreeBSD - you can configure the timezone to UTC by removing /etc/localtime. I don't know if this is actually a legitimate way to set it to UTC, but it was the only way I knew of until now, and it does seem to cause a problem with Tcl's clock scan.

% clock scan "2007-11-01" -format "%Y-%m-%d"
time value too large/small to represent
% clock scan "2007-11-01" -format "%Y-%m-%d"
1193875200

The call always fails the first time in each process, and seems to work for all calls thereafter. (including in other interps)

If you configure the timezone to UTC by instead making /etc/localtime a link to /usr/share/zoneinfo/Etc/UTC the problem doesn't occur. I have a number of systems configured with no /etc/localtime - but I guess I'll change that now in light of this.

This issue also shows up in the FAQ on http://amsn-project.net/ .

Is a missing /etc/localtime something that clock scan should be able to handle - or is it would it be considered an OS configuration issue?

DKF: Ultimately, I'd consider this to be OS misconfiguration as it feels like stating that the system has no local timezone instead of that it is UTC.


sbron 2009-06-14 - Since Tcl 8.5, clock scan is very relaxed about the dates it accepts (it sees no problem in "March 0" or "April 34"), so it can no longer be used directly for validation. That's why I wrote my own Time and date validator.

RLH I am sure there was a reason that clock will accept invalid dates. I cannot for the life of me think of one though.

Mat Since this might break a lot of existing code, I hope that reason was a good one.. ;)

LV I wonder why this problem now exists.

TCV (2013-02-11) Note that providing only a year (e.g. %Y) in the format string will not produce the time as of January 1st of that year. Similarly, providing only the year and month (e.g. %m/%Y) in the format string will not produce the time as of the 1st of that month. In both of these cases, you will instead get the time corresponding to midnight on the current day.