Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is clock scan incapable of detecting invalid dates?

40 views
Skip to first unread message

Paul Medeiros

unread,
Dec 11, 2017, 6:43:24 AM12/11/17
to
The following command:

clock format [clock scan "38:00 01/48/2016" -format "%R %D"] -format "%R %D"

Results in: 14:00 02/18/2016

Is clock scan really this broken? I have tried various format strings, but clock scan never throws an error when I give it invalid dates. It doesn't know that there are not 38 hours in a day and no month has 48 days?

I gave up on clock scan and now use [exec date ...] (on linux). I wonder if this is a well known problem/feature or have I misunderstood something.

Andreas Leitgeb

unread,
Dec 11, 2017, 7:21:40 AM12/11/17
to
Paul Medeiros <medei...@gmail.com> wrote:
> The following command:
> clock format [clock scan "38:00 01/48/2016" -format "%R %D"] -format "%R %D"
> Results in: 14:00 02/18/2016
> Is clock scan really this broken? I have tried various format strings,
> but clock scan never throws an error when I give it invalid dates.
> It doesn't know that there are not 38 hours in a day and no month
> has 48 days?

It knows, as you can see by that it wraps the extra days into next
month, and extra hours into next day.

You probably mix up date conversion with date validation. Tcl only
does the former.

If you're working with fixed format, you could also construct a
scan format, and validate the fields, before passing them to
clock.

> I gave up on clock scan and now use [exec date ...] (on linux).
> I wonder if this is a well known problem/feature or have
> I misunderstood something.

Java's "SimpleDateFormat" has a boolean attribute to request strict
or lenient parsing. Tcl only has lenient parsing. Feel free to
write a TIP for a flag (for clock scan) to trigger strict parsing.

Arjen Markus

unread,
Dec 11, 2017, 9:41:34 AM12/11/17
to
On Monday, December 11, 2017 at 1:21:40 PM UTC+1, Andreas Leitgeb wrote:
Come to think of it:
A simple check could be:
The original string must be reconstructed if the date/time is valid.
Of course you will need to have a specific format to do this.

Not entirely sure this will work in 100% of the cases ;).

Regards,

Arjen

Georgios Petasis

unread,
Dec 11, 2017, 12:23:35 PM12/11/17
to
Well, it is less than a month that I complained about clock scan
misbehaving in the thread "Why I am getting wrong results from clock scan?":

clock format [clock scan {2004-10} -format {%Y-%m}]

My opinion is that is not reliable even for valid dates. Let alone
invalid ones.

George

Schelte Bron

unread,
Dec 11, 2017, 3:51:04 PM12/11/17
to
Arjen Markus wrote:
> A simple check could be:
> The original string must be reconstructed if the date/time is
> valid. Of course you will need to have a specific format to do
> this.
>
You mean something like http://wiki.tcl.tk/23761?


Schelte

0 new messages