clock scan "next wed" is wrong?
Closed / Wont Fix1160695fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2005-03-10 15:36:22
Using clock scan "next <dayname>" seems to go 2
weeks ahead, rather than 1, why is that? This affects
both the 8.4 line and 8.5.
telhp6:/home/dcollins/tmp/tcl8.5a2/unix$ date
Thu Mar 10 15:23:16 GMT 2005
clock format [clock scan "+1 wed"] -format "%Y-%m-%
d"
2005-03-16
clock format [clock scan "-1 wed"] -format "%Y-%m-%d"
2005-03-09
clock format [clock scan "next wed"] -format "%Y-%m-
%d"
2005-03-23
clock format [clock scan "last wed"] -format "%Y-%m-%
d"
2005-03-09
I can use +1 wed and -1 wed instead which seem to
work fine, but I mentally assumed that last/next was the
same as -1/+1, have I got it wrong?
I tracked the "problem" to something in the yacc
grammer (Below). If I change the yyDayOrdinal to 1,
then I get the "correct" results, but it looks like it was
designed this way, so does the help need updating?
| tNEXT tDAY {
yyDayOrdinal = 2;
yyDayNumber = $2;
}
This is probably obselete in 8.5 with the new clock
scan, but what's the equivalent 8.5 syntax?
dkf Ticket [1160695fff]: 2 changes
[History diff]2005-03-10 22:38:32
kennykbplain2005-03-15 23:05:03
Logged In: YES user_id=99768 In the [clock] grammar, "next Wednesday" is interpreted as "Wednesday week." This is surely unexpected, but I'm afraid to change it at this late date, since it has always worked that way. And, lordy, you seem to have found a bit of a hole in the 8.5 replacements - there doesn't seem to be a direct replacement for this. I probably need to add more stuff to [clock add] along the lines of [clock add $date 1 Wednesday]. Which will take another TIP. Oh, joy.
kennykbplain2005-04-14 03:44:54
Logged In: YES
user_id=99768
As I started writing a TIP for an enhancement to
[clock add] to handle the case of "next wednesday"
by a syntax like [clock add $date 1 Wednesday], I
realized that such syntax, if localised, would open
a can of worms in those locales where months and
weekdays can have the same names (Mandarin Chinese
has this problem, because both months and weekdays
are simply known by their numbers.)
But in hacking at the implementation, I realized
that there is a (slightly awkward) way of
approaching the problem:
# Find the start of the current date
set date [clock scan 0000 -format %H%m]
# Find the start of Wednesday of the current
# week, and advance to "next Wednesday"
set wed [clock scan Wednesday \
-base $date -format %a]
if { $wed <= $date } {
set wed [clock add $wed 1 week]
}
# Alternatively, find the start of Wednesday
# of the current week, and retreat to
# "last Wednesday"
set wed [clock scan Wednesday \
-base $date -format %a]
if { $wed >= $date } {
set wed [clock add $wed -1 week]
}
While this is a trifle more verbose than a simple
[clock scan "next Wednesday"], it has the
advantage that it will be correctly localised
automatically (replace Wednesday with a day name
in the locale specified by the -locale argument to
[clock scan], and it'll still work), and it
needs no additional magic in the 8.5 [clock]
command to make it go.
Is this usage acceptable?
kennykb Ticket [1160695fff]: 1 change
[History diff]2005-04-14 03:50:04
dwcollinsplain2005-04-14 17:12:00
Logged In: YES user_id=1093010 That looks reasonable to me. I hadn't realised that some languages had the same syntax for days and months (confusing or what!) Anyway, I managed to workaround it in 8.4, and your 8.5 solution is only a few lines (which the user could always wrap up into a little procedure if they needed to), so I'd say go with that. For 8.4 I ended up calculating the number of days to when I wanted to poll and adding that to my time (kind of similar to what you did with adding 1 week).
kennykbplain2005-04-19 22:22:23
Logged In: YES user_id=99768 OK, since there is a "right way" to do it in 8.5, and fixing it is likely to break existing code in 8.4 (given that "it's always worked that way"), I'm closing the bug report.
Log in (anonymous is fine) to add a comment.