Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 2b3b6309186e36566dd875614e9d71f244a588dc4df8f9743be9b438fef939e3
Ticket: 7bad415e3ec8baf40d087374000fbcbab511689c
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
User & Date: kenneth.kienle on 2026-09-03 19:55:01
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-markdown"
  4. comment changed to:
    **8.6: the bug of [51aa53616067cb63] is still there.** `generic/tclGetDate.y`'s
    rule `zone: sign tUNUMBER` computes `-$1*($2 % 100 + ($2 / 100) * 60)`, so
    every signed number is hhmm and `+02` is two *minutes*. The tz project's
    abbreviations for zones without a letter name are `+02`, `-03`, `+0530`
    (hh or hhmm), so any zoneinfo-derived `%Z` of that form round-trips
    wrongly through the free-form scanner, 7,080 s off for `+02`:
    
        % clock scan "2023-11-15 00:13:20 +02" -gmt 1
        1700007080          ;# expected 1700000000
        % clock scan "2023-11-15 00:13:20 +0200" -gmt 1
        1700000000
    
    Tcl's own suite cannot see it because `tools/tclZIC.tcl` pads every `%z`
    abbreviation to `%+03d%02d`; a build reading system zoneinfo fails
    `clock-59.2` on exactly this, which is how [51aa53616067cb63] was found.
    That ticket was fixed for 9.x in [a37536d4d7] and [7018ffb43e] and closed
    with: *"I am unsure I shall backport it to 8.6, but if yes theoretically
    it may be possible only partial, because I don't know earlier bison/yacc
    versions support semantic predicates."* 8.6.18 (2026-05-11) shipped
    without it. The attached backport uses **no semantic predicate**, only a
    plain action, so it compiles with whatever bison built the shipped
    `tclDate.c`.
    
    **9.x: the fix takes the wrong digit count when a number follows the
    zone.** `yyDigitCount` is the lexer's count for the *last* number it read.
    The parser cannot reduce `sign tUNUMBER` without a lookahead (the same
    prefix opens `sign tUNUMBER tDAY` and the relative `sign tUNUMBER unit`),
    and when the lookahead is itself a number the count already belongs to
    it. So `nmzone` reads `+02 2023-11-15` by 2023's four digits, and reads
    `+0200 15 Nov 2023` by 15's two, which 8.6.18 gets right:
    
        % clock scan "+0200 15 Nov 2023 00:13:20" -gmt 1
        1699935200          ;# 9.0.4; 8.6.18 returns 1700000000
    
    **Fix** (attached `clock-freescan-hh-zone-lookahead-safe.patch`, 30 lines
    against core-8-6-branch, `tclGetDate.y` and the shipped `tclDate.c`
    alike): one or two digits are hours, as 9.x rules; and the lexer keeps the
    previous count (`datePrevDigitCount`, saved before each overwrite) so the
    action can choose by the lookahead's token type — `yychar`, bison's
    documented action variable, against `tUNUMBER` and `tISOBASE`, the two
    tokens the number path produces:
    
        int digits = (yychar == tUNUMBER || yychar == tISOBASE)
                ? yyPrevDigitCount : yyDigitCount;
        yyTimezone = -$1*(digits <= 2 ? $2 * 60 : $2 % 100 + ($2 / 100) * 60);
    
    Both counts are initialized with the rest of `DateInfo`. The same idea
    transfers to 9.x's `nmzone`.
    
    **Verification:** the attached `tcl-tz-repro.tcl` (also on
    [832d098fdfec8f004cf1c8e8836f7c335da12d54]) has seven `clock scan` checks:
    stock 8.6.18 fails four (`+02`, `-02`, `+3`, and `+02 2023-…`), stock
    9.0.4 fails two (`+02 2023-…`, `+0200 15 Nov …`), patched 8.6.18 none;
    `+2 days` and `+14 days` relatives unchanged; `clock-59.2`'s six pairs
    round-trip against system zoneinfo; `tests/clock.test` shows no new
    failure. Proposed: the seven lines as a `clock-59.x` block beside
    `clock-59.2`.
    
  5. foundin changed to: "8.6.18, 9.0.4"
  6. is_private changed to: "0"
  7. login: "kenneth.kienle"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "39c7f150e83208e701f26c9bf329dc8b2f4bc4d1"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "kenneth.kienle"
  14. subsystem changed to: "06. Time Measurement"
  15. title changed to:
    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
    
  16. type changed to: "Bug"