|
2008-07-31
| ||
| 01:23 | • Ticket [2010909fff] clock scan fails with %V status still Open with 7 other ... artifact: 6e8908b78d user: kennykb | |
|
2008-07-07
| ||
| 17:30 | • Ticket [2010909fff]: 4 changes artifact: d13a377f14 user: ferrieux | |
| 01:34 | • Open ticket [2010909fff]. artifact: 87a1d13180 user: kennykb | |
|
2008-07-05
| ||
| 22:53 | • Ticket [2010909fff]: 4 changes artifact: 3e65ae5cd0 user: ferrieux | |
| 06:50 | • Ticket [2010909fff]: 4 changes artifact: 20f1502b0e user: kennykb | |
| 06:36 | • Ticket [2010909fff]: 4 changes artifact: d451fbe403 user: ferrieux | |
| 05:02 | • Pending ticket [2010909fff]. artifact: 12ee0beb05 user: kennykb | |
| 03:46 | • Ticket [2010909fff]: 2 changes artifact: 2a06d6e863 user: andreas_kupries | |
|
2008-07-04
| ||
| 19:54 | • New ticket [2010909fff]. artifact: 3d88d36afd user: haertel | |
clock scan fails with %V
Open2010909fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-07-04 19:54:12
The clock scan command returns always the current week when the given format only contains the week (%V).
test-case showing failure
for {set week 0} {$week < 22} {incr week} {
set x [clock scan "$week 2008" -format "%V %Y"]
puts [clock format $x]
}
However it works correctly when a week day is supplied.
test-case workaround
for {set week 0} {$week < 22} {incr week} {
set x [clock scan "$week Sun" -format "%V %A"]
puts [clock format $x]
}
This could be a fix in the code. In that it assumes the current day.
Or this could be a fix in the documentation. In that it is clearly stated that for the scan and format %V the week day shall be supplied to.
From my point of view I'd prefer a fix in the code. Primarily because clock already assumes in the workaround that the year is the current year.
andreas_kupries Ticket [2010909fff]: 2 changes
[History diff]2008-07-05 03:46:21
kennykbplain2008-07-05 05:02:41
Logged In: YES
user_id=99768
Originator: NO
A careful reading of clock.n (under SCANNING TIMES) shows that
[clock] here works as designed and documented. I concede that
the behaviour of ignoring the 'week' format group in that case
is puzzling, but it fits with the fact that redundant groups
are (and must be) ignored in other cases - for instance,
in parsing an RFC2822 date, the day-of-the-week is presented
even though the other fields are sufficient to specify the date.
It is easy to parse a date like 2008-W27 if you need the
start of the week:
set date {2008-W27}
set secs [clock scan "$date-1" -format "%G-%V-%u"]
Another reason for the code to work the way it does is that
otherwise there is also a possibility of nonsense combinations
like "%G-%u" without a week number - either choosing a given
weekday in the first week, or a given weekday in the current
week number, would be surprising.
ferrieuxplain2008-07-05 06:36:22
Logged In: YES user_id=496139 Originator: NO Sorry, but I don't understand the reference to redundant groups: here we are on the other end of the spectrum -- underspecified rather than redundant. When we parse "2008 23" with "%Y %H" we get a similar situation, but the result is compatible with all specified data, it is a date whose time-of-day is 23:00 in year 2008. The same with %V violates the compatibility rule since it gives noon today, and today is not in week 01.
kennykbplain2008-07-05 06:50:56
Logged In: YES user_id=99768 Originator: NO You're right, but... if underspecified ones are allowed from both ends, then an anomaly results with: 2008-5 in place of 2008-W27-5 or 2008-04 in place of 2008-07-04 Is that "a completely specified 2008 (meaning the start of the year) together with a redundant day of week or month"? A completely specified "'day 4 of the current month' with a redundant year" or "'day 5 of the current week' with a redundant year"? "A specification that means day 4 of the month in 2008 corresponding with the base month" or "day 5 of the week in 2008 corresponding with the base week"? An error? Something else? Rather than worry about what the combination of under- and over-specified dates means, I punted, and said "there must be enough information in the specification to identify a unique day" I'm willing to revisit it, if someone wants to spec it out in a TIP.
ferrieuxplain2008-07-05 22:53:24
Logged In: YES user_id=496139 Originator: NO Hmm, you seem to be concentrating on under-specification of the input string, while I think it is useful to define it for the format string instead (the only circumstance under which "2008 04" should be reasoned about ex nihilo, is free-form-scanning. We are not in this case, we do have a format string.). Then, we can define the "compatibility principle" in a very simple fashion: [clock format [clock scan $s -format $f] -format $f] is always "nearly equal" to $s (except for whitespace and other irrelevant chars) This means that for "underspecified formats" like "%Y %V", [clock scan] is free to *choose* (as in "not specified") among several values, provided the above equation holds. This choice can be driven by simplicity of implementation, or by some objective function to optimize (like "closest to now"). Kevin, don't you think this compatibility principle would be a good guide ? If we admit it, then clearly the current behavior with %V is a bug... (But please also notice that enforcing it would not require a TIP, since I can't imagine a purposeful use of "%Y %V" returning a date in the wrong week for example).
kennykbplain2008-07-07 01:34:04
Logged In: YES user_id=99768 Originator: NO The cases that worry me are the ones that might be best described as "simultaneously overdetermined and underdetermined". [clock scan] is documented to ignore excess fields - even if they are inconsistent. "7 juillet 2008 lundi" with format "%d %B %Y %A" and -locale fr parses correctly as 2008-07-07 even though it is not a Monday. (This is much easier than attempting consistency checks for things like RFC2822 dates.) The issue then is one of determining which rule to apply when there are two sets of data, both underdetermined. Consider [clock scan "2008-1" -format "%G-%u"] That's one of the cases where I can't quite manage to figure out The Right Thing. With your proposal, we have two incomplete data items: the year (which should then default to 1 January of that year), and the day of the week (which should default to Monday of the week of the base date). What ought they to do in combination? Should one take precedence (if so, which?), or should this be an error, or is there another rule that should apply?
ferrieuxplain2008-07-07 17:30:38
Logged In: YES
user_id=496139
Originator: NO
The idea is to think about format groups as constraints, hence each providing a (possibly large) *set* of solutions, instead of just a default value. Then the job of [clock scan] can be defined as returning *any* value within the intersection of all sets:
"1993 4" / "%Y %V" --> any value on week 4 of 1993
And again, picking a value in the intersection may be completely driven by the will of the implementor of [clock]. No value is worse than another in that respect !
In the case of empty intersection (inconsistent fields like your example), it may use a predefined ordering of the constraints and return a value in the first nonempty intersection during relaxation:
"7 juillet 2008 jeudi" / "%d %B %Y %A" -->
predefined order of relaxation: %A..%d..%B..%Y
first nonempty after relaxing: %A
final intersection: %d,%B,%Y
Tha above remark about "freedom of choice" means that
[clock scan "2008-1" -format "%G-%u"]
is free to return any monday of 2008. It currently returns the next Monday starting from today, which is a valid choice, just as would have been the first Monday of 2008. So I think your worries about The Right Thing are virtual...
Do you have in mind a case breaking that compatibility principle ?
kennykbplain2008-07-31 01:23:59
data_type - 360894
Log in (anonymous is fine) to add a comment.