Repository navigation
feat(ui): show the cache time in the viewer's locale and time zone - #564
Conversation
WilhelmZA
left a comment
There was a problem hiding this comment.
Reviewed at c27b538d.
formatTimestamp() parses the backend's naive UTC timestamp as UTC and formats it in the viewer's locale and time zone, and input that does not match is returned unchanged. The web.text.cache_icon default loses its UTC suffix in the model, the sample, both docs pages and the UI fixture, and CHANGELOG.md records it under Changed with a migration note. CI gate passes and both commits are verified.
Before approval:
- #551 says it depends on #534 and #542 being merged, because both edit
results/individual.tsx. #534 is merged and #542 is still open. This PR does not touch theisErrororerrorMsgcode, so either merge #542 first and rebase, or note on #551 that the dependency on #542 is dropped.
#544 adds web.text fields in the same model block, docs tables and UI fixture, and #565 moves the cacheLabel line into ResultPanel. #566 and #567 also edit CHANGELOG.md.
Nits:
CHANGELOG.md: the new entry links only #551. The other Unreleased entries link the PR and the issue.hyperglass/ui/util/timestamp.test.ts: the tests assert exact ICU output such as'Nov 20, 2026, 3:00:00 AM EST'. Those strings come from the CLDR data that ships with Node, so a Node update can fail them without a code change. One exact string as a smoke check andformatToPartsfor the rest would be more stable.
|
Thanks.
|
WilhelmZA
left a comment
There was a problem hiding this comment.
Approving at 06a7ee1e.
The new commit changes only CHANGELOG.md and hyperglass/ui/util/timestamp.test.ts. The tests now build each expected instant with Date.UTC and compare against Intl output, so they still fail if the UTC parsing, the time zone conversion or the pass-through of unmatched input breaks, and one exact string stays as a smoke check. The changelog entry links the PR, and the comment on #551 drops the dependency on #542. CI gate passes and all three commits are verified.
#542, #544 and #565 still overlap with this PR in results/individual.tsx and the web.text files, so the later ones need a rebase.
The backend sends the query timestamp as naive UTC ("2026-11-20 08:00:00"),
and the cached-result tooltip showed it as received after "Cached from".
Add formatTimestamp(), which parses such values as UTC (a value with its own
zone keeps it) and formats them with Intl.DateTimeFormat in the viewer's
locale and time zone, on a 24-hour clock with the zone name. Unparseable
input is returned unchanged.
The time is no longer UTC, so the default web.text.cache_icon drops the
word: "Cached from {time}".
Format with dateStyle "medium" and timeStyle "long" instead of forcing hourCycle h23. The locale decides the 12- or 24-hour clock, as #551 specifies, and the long time style keeps the zone name or offset. A forced h23 was also only partial: some locales (fr-CA, ko-KR, th-TH) use their own long pattern once a zone name is requested. Accept only the backend's "YYYY-MM-DD HH:MM:SS" and ISO 8601 date-times (T, optional fraction, Z or offset), with range checks. dayjs accepted "12" or "abc 2026" as dates and rolled "2026-13-45 99:99:99" over, so non-timestamps were not returned unchanged. The cache tooltip test now compares with formatTimestamp under a pinned time zone, so it passes in any runner locale. Add the backend default test for cache_icon, and link #551 in the changelog.
…R strings Keep one exact string as a smoke check. The other cases format a known instant with the same Intl options, so a Node or ICU update that changes the CLDR text can't fail them without a code change. Link the PR in the changelog entry.
|
Rebased onto
CI here fails until #571 merges: |
06a7ee1 to
b19100a
Compare
WilhelmZA
left a comment
There was a problem hiding this comment.
Approving at b19100af.
This is the rebase onto main after #544 and #526. The three commits carry the same changes I approved at 06a7ee1e: the range diff shows only context differences in the UI fixture (it keeps asPathTitle from #544) and in test_web_config.py. CI gate passes on the run that merged this head into main at f89ab22a. The one commit on main since then is #545, which changes only the query form files and none of the files or text keys this PR touches, and the merge with current main is clean. All three commits are verified.
#542 and #565 still change results/individual.tsx, so the later ones need a rebase.
Piece T1 of #550. Base:
main. Port of hyperglass-ng PR jsenecal#138.Problem
The backend sends the query timestamp as naive UTC:
Query.__init__setsdatetime.now(UTC).strftime("%Y-%m-%d %H:%M:%S"), for example2026-11-20 08:00:00, and a cache hit returns the stored copy of that string. The cached-result tooltip incomponents/results/individual.tsxshowed it as received, through the defaultweb.text.cache_iconCached from {time} UTC. Viewers had to convert it to their own time.That tooltip is the only absolute timestamp the UI shows a viewer. The other uses were checked and are left alone, as #551 says:
components/output/fields.tsxAge) is a relative age ("an hour"). Its tooltip holds the absolute time fromdayjs.utc(...).toString(), labelled UTC, which is correct.hooks/use-table-to-string.ts) writesTimestamp: <timestamp> UTCand the route age with a UTC time. That text is pasted into tickets and compared with router logs, so it stays in UTC, and it is correct.Change
util/timestamp.ts(new):formatTimestamp(value, { locale?, timeZone? }).YYYY-MM-DD HH:MM:SSand ISO 8601 date-times (T, an optional fraction, an optionalZor±HH:MMoffset), checked with a strict pattern and field ranges. A value without a zone is UTC. A value withZor an offset keeps it.12,abc 2026,2026-13-45 99:99:99,2026-02-30 00:00:00and a date without a time. The fork's helper useddayjs.utc, which accepted the first two as dates and rolled the third over into 2027.Intl.DateTimeFormatand{ dateStyle: 'medium', timeStyle: 'long' }, in the viewer's locale and time zone (both can be overridden, which the tests use). The locale decides the 12- or 24-hour clock, as Cached-result time is shown in UTC instead of the viewer's time zone #551 says. The long time style includes the zone name or offset (for exampleEST,GMT+9,UTC−5, depending on the locale and zone), so a local time can't be mistaken for UTC. The month is written out, so11/20and20/11can't be confused inen-US.components/results/individual.tsx: the tooltip passesformatTimestamp(data.timestamp)as{time}. The diff is the import and thecacheLabelline only. It doesn't touch theisError/errorMsgcode (fix(ui): flag a failed query that has no error body #542) or the header buttons (fix(ui): give the icon-only result buttons an accessible name #534).web.text.cache_icondefault:Cached from {time} UTC→Cached from {time}(models/config/web.py,.samples/sample_config.yaml,complete-config.mdxsample and table,web-ui.mdxtable, regenerated UI fixture).CHANGELOG.md: a Changed entry with the default change.Tests
util/timestamp.test.ts(new, 14 tests):Zare parsed as UTC;Z,+02:00and a fractional-05:30value keep their zone.GMT+9).12:00:00 AM ESTinen-USand00:00:00 GMT-5inen-GB;de-DEgives20.11.2026, 09:00:00 MEZ.Asia/Kolkatawithvi.stubEnv('TZ', …), so reading a value as local time gives a different hour even on a UTC runner. CI runs in UTC, where local and UTC parsing look the same.components/results/individual.test.tsx: the cache tooltip test (added in test(ui): cover results, layout and the index page #505) asserted the current behaviour,Cached from 2026-11-20 08:00:00 UTC. It now pinsTZ=America/Toronto, computesexpected = formatTimestamp(timestamp, { timeZone: 'America/Toronto' })in the runner's locale, checks thatexpecteddiffers from the raw value, and asserts the tooltip text is exactlyCached from ${expected}. It passes withLC_ALLset toC,fr_CA,fr_FR,ko_KR,th_TH,ar_EGandfa_IR, and withTZ=Pacific/Auckland.models/tests/test_web_config.py:Text().cache_icon == "Cached from {time}". It fails with the old default.Without the fix (
origin/main'sindividual.tsxand fixture, new tests):Mutations (each run of
util/timestamp.test.ts+individual.test.tsx, 37 tests):new Date(y, m, …)instead ofDate.UTC)new Date(value)before the strict pattern2026-02-30)24:00:00)+25:00)hourCycle: 'h23'timeStyle: 'medium'(no zone)Invalid Dateinstead of the inputindividual.tsxcache_icondefaulttest_cache_icon_default_has_no_time_zonefailsWith the fix:
testTests 228 passed (228)on Node 22. Also on Node 24 withLC_ALL=fr_CA.UTF-8 TZ=Pacific/Auckland.biome format,biome lintandtsc --noEmitare clean.4171 passed, 4 skipped;ruff check .is clean.Changelog
web.text.cache_iconis nowCached from {time}; it wasCached from {time} UTC.Notes
web.text.cache_iconto the old text keeps the wordUTCafter a now-local time, for example… 3:00:00 AM EST UTC. Remove the setting or the wordUTC. The CHANGELOG entry says so.Closes #551