| Ticket UUID: | 7bad415e3ec8baf40d087374000fbcbab511689c | ||
| Title: | Free-form clock scan reads "+02" as two minutes in 8.6 (backport of [51aa53616067cb63] without semantic predicates); the 9.x fix misreads a zone followed by a number | ||
| Type: | Bug | Created on: | 2026-09-03 19:55:01 |
| Submitter: | kenneth.kienle | Assigned to: | nobody |
| Subsystem: | 06. Time Measurement | Severity: | Important |
| Priority: | 5 Medium | Last modified: | 2026-09-10 22:28:45 |
| Status: | Open | Closed by: | nobody |
| Resolution: | None | Closed on: | |
| Version: | 8.6.18, 9.0.4 | ||
| Description: | ||||
|
8.6: the bug of [51aa53616067cb63] is still there.
Tcl's own suite cannot see it because 9.x: the fix takes the wrong digit count when a number follows the
zone.
Fix (attached
Both counts are initialized with the rest of Verification: the attached | ||||
| User Comments: | ||||
oehhar added on 2026-09-04 12:20:23:
Kenneth, thanks for the proposals, look great. Sergey the clock wizard will hopefully comment. Thanks for all, Harald sebres added on 2026-09-04 12:25:27:
Although, IMHO, it is not standard order for a timestamp (TZ before time), I am unsure free-scan really shall scan that, but I'd take a look at this later. kenneth.kienle added on 2026-09-08 05:59:54:
Sergey, You are right about the ordering. The zone-first cases are now in their own test, clock-59.5. If you decide free-form scan should not accept a zone before the time, delete that one test and nothing else changes. That test is the only coverage of the tISOBASE half of the lookahead check. I measured this - remove the tISOBASE clause and clock-59.5 is the only test that fails. So if the zone-first order goes, that clause can go with it. How this came up: I build and test Tcl 8.6 against the system's tzdata rather than the bundled copy. Running the 8.6 suite in that configuration is what surfaced it. The main bug is the trailing form:
Stock 8.6.18 returns 1700007080. The correct value is 1700000000. A signed zone is read as hhmm whatever its length, so "+02" becomes two minutes. That is how the system zoneinfo writes the %Z abbreviation, so clock format output does not survive a round trip through clock scan (Tcl's bundled tzdata writes "+0200" for %Z, which is why clock-59.2 passes today. %z is always four digits and is never affected). The clearest demonstration is to build 8.6 without bundled tzdata and run clock.test. Stock fails clock-59.2, and with this branch it passes. On a system whose zoneinfo also lacks CET, US/Eastern and US/East-Indiana you will see clock-30.33, 30.34, 39.1 and 44.1 fail as well, in stock and in the branch alike. Those are missing-zone errors from the tzdata install rather than anything to do with this bug, and I should not have listed them alongside 59.2. The branch is bug-7bad415e3e-8.6. It uses no semantic predicate, because your comment on [51aa53616067cb63] raised the older-bison question. The existing "sign tUNUMBER" action decides hours or hhmm itself. When the parser holds a numeric lookahead, it reads the digit count recorded before that lookahead. tclDate.c was regenerated with bison 3.8.2 by gendate. 14 shift/reduce conflicts, the same as stock. The branch also initialises the two digit-count fields in
TclClockOldscanObjCmd. That function sets every other The read is real and I can move it, but only from C. Seeding yyDigitCount with 3 or more before the parse changes
from 1699916400 to 1699919940. Seeding yyPrevDigitCount alone changes nothing: the keyword path assigns that field and never assigns yyDigitCount, which is the one "number: tUNUMBER" reads. What I could not do is reach it from a script - stock as shipped gives 1699916400, and so does stock after a preceding clock scan of {1234}, {20231115 001320}, {12} or {1130}, because the stack slot does not carry over. Because of that, I have written no test. Without editing the C there is no build on which one would discriminate, so it would pass either way and be a false control. One behaviour change from the lookahead work itself:
That one is not the initialisation, removing those two lines leaves it at
Two measurements on 9.0.5, in case they are useful to you:
The second should differ from the first only in the year. This branch gives 1731622400, which is what glibc gives for the same instant written as a date it accepts: date -u -d '2024-11-15 00:13:20 +02' +%s. So 8.6 with this change and 9.0.5 disagree on a zone followed by a number. I think 9.x is the one to correct, I just didn't want the difference to be a surprise. My first version of this patch had the same kind of bug I am describing in 9.x: "last" is returned as tUNUMBER by LookupWord without passing the digit scanner, so "clock scan {+0200 last month}" regressed against stock. That is fixed and clock-59.6 pins it. A later check found that my ISO-base test no longer covered the clause it was written for, because I had changed it to a four-digit zone. That is fixed too. Both errors were mine. There are three related pre-existing issues I did not touch, I'm happy to file them separately if that is useful. I checked each against 9.0.5.
Kenneth kenneth.kienle added on 2026-09-08 06:09:53:
Two numbers dropped out of my previous comment. The renderer treated a line
beginning "1700003600." and one beginning "1700000060." as ordered-list
markers and consumed them. The sentences should read:
That one is not the initialisation, removing those two lines leaves it
at 1700003600.
Seeding the field with 3 or more does give stock's 1700000060.
Both values are in the table further up the comment, so nothing is
ambiguous, but the sentences read oddly without them. Nothing else changed.
sebres added on 2026-09-10 22:28:45:
Well, I'm still unsure how to handle this... I'd like to avoid change of 8.6 to cover this obscure case (ordering etc), due to compat reasons et al (don't underestimate the inventiveness of users in usage of free-scan formats). For 9.0 I'd probably partially cherry-pick this (at least the tests), but need more time to review. For example, I don't understand why the test successfully covers free-scan conversion of {2023-11-15 00:13:20 +02 2024}... IIRC, free-scan shall fail here with "more than one date in string" error (due to 2 years in input string). Another thing is that the lookahead supposedly increases yyDigitCount, what makes no sense to me (or rather it shall not at all). | ||||
Attachments:
- tcl-tz-repro.tcl [download] added by kenneth.kienle on 2026-09-03 19:55:47. [details]
- clock-freescan-hh-zone-lookahead-safe.patch [download] added by kenneth.kienle on 2026-09-03 19:55:47. [details]
