Skip to content

fix: read time picker ranges in the display time zone - #3445

Merged
karl-power merged 2 commits into
mainfrom
timezone-selector
Oct 23, 2026
Merged

karl-power merged 2 commits into
mainfrom
timezone-selector

Conversation

@karl-power

Copy link
Copy Markdown
Contributor

Summary

Fixes the time picker shifting ranges when "Use UTC time" is on and the browser is west of UTC, and makes the time range helpers take a time zone name so later PRs can add a time zone setting.

  • The search page wrote the range text in UTC, but the picker parsed and re-formatted it in the browser's zone. West of UTC, a range ending now parsed as future, got clamped to now, and Apply collapsed it to a zero-length range hours in the past.
  • parseTimeRangeInput, formatTimeRangeText, rangeNeedsExplicitYear, timeRangeInputToSeconds, dateParser and dateRangeToString take an IANA time zone (undefined = local) instead of an isUTC flag.
  • Parsing resolves relative words ("yesterday") against the date in that zone, and gives each date the offset in effect on that date, so ranges across a DST change round-trip.
  • The picker's start/end inputs show and read times in that zone, including their min/max dates.
  • New useDisplayTimeZone hook resolves the zone from the UTC preference. The picker, timeQuery.ts and the dashboard page use it.
  • common-utils: formatDate accepts timeZone; new toWallClock/fromWallClock helpers convert between instants and clock readings in a zone.

How this sets up the follow-up work

Follow-up PRs add a time zone selector in two places: User Preferences, where it replaces the "Use UTC time" switch as the global setting, and the search page time picker, where it overrides the global setting for that page. Both selectors keep UTC and Local at the top. This PR does the groundwork so those stay small:

  • Every time range helper and caller already takes an IANA zone name, so supporting any zone (e.g. Asia/Tokyo) needs no more parsing or formatting changes.
  • useDisplayTimeZone is the single place that decides the zone. The global setting only changes what this hook returns, and the search page override can wrap the page in a provider that the hook reads.
  • Named zones already round-trip across DST changes, which UTC-only support never had to handle.

How to reproduce

Setup: set browser time to west of UTC (Chromium: DevTools → ⋮ → More tools → Sensors → Location → "San Francisco")

On main:

  1. Enable UTC time
  2. Go to Search, open the time picker, make sure "Live tail ranges" is off, and click "Last 1 hour".
  3. The input shows the last hour in UTC, e.g. Oct 22 12:00:00 - Oct 22 13:00:00.
  4. Reopen the picker: Start time and End time both show the current San Francisco time (e.g. 06:00).
  5. Click Apply: the input becomes a zero-length range 7 hours in the past.

On this branch:

  1. Repeat steps 1–3.
  2. Reopen the picker: Start time and End time show 12:00:00 and 13:00:00.
  3. Click Apply: the range is unchanged.

References

  • Linear Issue: HDX-5741
  • Related PRs:

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Oct 23, 2026 12:15pm UTC
hyperdx-storybook Ready Ready Preview Oct 23, 2026 12:15pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 617d98b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Patch
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the review/tier-3 Standard — full human review required label Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Diff size: 351 production lines changed (Tier 2 max: < 250)
  • Cross-layer change: touches frontend (packages/app) + shared utils (packages/common-utils)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 6
  • Production lines changed: 351 (+ 289 in test files, excluded from tier calculation)
  • Branch: timezone-selector
  • Author: karl-power

To override this classification, remove the review/tier-3 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 114 in total (1.41%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 critical · 🟠 1 major · 🔵 1 minor

1 posted as inline comment(s) on the changed lines. 1 listed below.

Findings outside the changed lines

  • 🟠 packages/app/src/components/TimePicker/utils.ts:602 — Day-based relative ranges ('Last 7 days', 'Last 30 days') are off by an hour when they span a DST change → For day/week fragments, chrono's createRelativeFromReference only implies timezoneOffset, so parsedWallClock now rebuilds the date from its fields and fromWallClock gives it the offset in effect on that day. The result is 7 days ago at the same clock time, not 168h ago. Before this PR, parsed.date() returned exactly now − 7×24h. This applies to the local zone too (timeZone undefined resolves to the browser zone). So for 7/14/30 days after any DST change, 'Last 7 days' covers 167h or 169h instead of 168h. Worse, DBDashboardPage.tsx:2166 stores timeRangeInputToSeconds('Last 7 days') as 601200 or 608400 in savedDateRange, and that value is persisted. Fix: treat results tagged result/relativeDate (or any result whose date comes from the reference instant) as exact instants and return parsed.date(). Add a test that timeRangeInputToSeconds('Last 7 days', 'America/New_York') returns 604800 with the clock set to 2026-11-03.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect time-range behavior across search and dashboard workflows.

Fix the repeated-hour comparison before merging; it can turn a recent search into an empty range.

Fix All in Claude CodeFindings

  1. P1 Recent searches become empty ▶

Summary

Makes the time picker read and show ranges in the display time zone.

  • The time picker reads and applies dates in the display time zone.
  • Search and dashboard ranges use the same display time zone.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Display time zone] --> B[Time picker]
  B --> C[Parse range text]
  C --> D[Search instants]
  D --> E[Format range in display zone]
  E --> B
Loading

Reviews (3) · Last reviewed commit: "fix: keep exact instants across DST chan..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 459 passed • 1 skipped • 1373s

Status Count
✅ Passed 459
❌ Failed 0
⚠️ Flaky 0
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This PR fixes a real user-facing bug (time-picker range shifting under "Use UTC time" west of UTC) and the refactor is type-safe end to end — the isUTC: boolean → timeZone: string | undefined signature change means any missed call site would fail typecheck, and the build/E2E are green. The prior greptile P1 (repeated autumn-hour instant shift) is addressed: explicit-offset timestamps return parsed.date() unchanged via the parsed.isCertain('timezoneOffset') branch, with a regression test covering both occurrences. Remaining items are a test gap and nits.

🟡 P2 -- recommended

  • packages/common-utils/src/core/utils.ts:810 -- fromWallClock (and fromDateInputValue) have no coverage for spring-forward gap times, where the typed wall clock does not exist in the zone and zonedTimeToUtc silently resolves to an adjacent instant.
    • Fix: Add a test exercising a non-existent local time (e.g. 02:30 on a US spring-forward day) through fromWallClock/fromDateInputValue and assert the chosen instant, documenting the intended behavior.

🔵 P3 nitpicks

🔵 P3 nitpicks (4)
  • packages/common-utils/src/core/utils.ts:764 -- formatDate now accepts both isUTC and timeZone, two ways to express one intent, which invites callers to set conflicting values.
    • Fix: Track removal of the isUTC parameter once the follow-up migrates useFormatTime/DBRowTable to useDisplayTimeZone, leaving timeZone as the only knob.
  • packages/app/src/components/TimePicker/TimePicker.tsx:76 -- DateInputCmpProps types minDate?: Date | null but maxDate?: Date, an asymmetry that is not load-bearing and reads as accidental.
    • Fix: Align the two to the same nullability unless the difference is intentional.
  • packages/app/src/timeQuery.ts:30 -- dateRangeToString declares timeZone: string | undefined (required argument) while the helper layer below it uses optional timeZone?: string, an inconsistent convention across the new surface.
    • Fix: Standardize on timeZone?: string for the whole helper family.
  • packages/app/src/components/TimePicker/__tests__/TimePicker.test.tsx:58 -- the display-value assertions use .not.toHaveLength(0), which passes as long as any matching input exists and would not catch a duplicated or misrendered field.
    • Fix: Assert the exact expected count (or target the specific inputs) so the test fails on unexpected matches.

Reviewers (8): correctness, adversarial, testing, maintainability, project-standards, kieran-typescript, julik-frontend-races, previous-comments.

Testing gaps: DST spring-forward (non-existent wall clock) path through fromWallClock/fromDateInputValue is untested; toDateInputValue/fromDateInputValue round-trip across a DST boundary is not directly asserted.

Deferred (not blocking): useFormatTime and DBRowTable still read isUTC directly while the picker reads useDisplayTimeZone; the author confirms this converges in a follow-up PR. No behavioral divergence exists in this PR because useDisplayTimeZone maps the UTC preference to Etc/UTC, which formats identically to the existing isUTC path.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

Comment thread packages/app/src/useDisplayTimeZone.ts Resolved
Comment thread packages/app/src/useDisplayTimeZone.ts Resolved
With "Use UTC time" on, the search page writes the range text in UTC but
the time picker parsed and re-formatted it in the browser's zone. West of
UTC a range ending now parsed as future, got clamped to now, and Apply
collapsed it to a zero-length range hours in the past.

- Time range helpers take an IANA time zone instead of an isUTC flag, and
  parse in that zone with each date's own offset across DST changes
- The picker's date inputs show and read times in that zone
- useDisplayTimeZone resolves the zone from the UTC preference
- Add toWallClock/fromWallClock and a timeZone option to formatDate
Comment on lines +62 to +64
const nowInstant = currentDate();
const now = toWallClock(nowInstant, timeZone);
const parsedDate = parsedWallClock(parsed, timeZone);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Recent searches become empty

normalizeParsedDate compares clock readings before returning the original instant. When New York clocks fall back at 2026-11-01T06:00:00Z, Past 30m starts at 05:30Z, whose clock reads 01:30. Now reads 01:00, so the parser treats that past start as future and clamps it to now. The range becomes empty, hiding the requested logs.

Compare known instants against nowInstant before applying the future-date clamp. Add a test for a short range crossing the rollback; the existing Past 1h test has equal start and end clock readings and misses this case.

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

@karl-power
karl-power merged commit dab6eb8 into main Oct 23, 2026
31 checks passed
kodiakhq Bot pushed a commit that referenced this pull request Nov 4, 2026
## Summary

Adds a time zone selector to the time picker on the search and dashboard pages. It overrides the User Preferences time zone for that page only and is kept in the `tz` URL param.

- `TimeZoneOverrideProvider` reads `tz`; `useDisplayTimeZone` prefers it over the user setting, so everything on the page switches together. Unknown values are ignored.
- The picker input shows the zone in use (e.g. `UTC-7`), highlighted when it isn't the browser's. The popover ends with the selector plus "Default", "UTC" and "Local" buttons; User Preferences gets "UTC" and "Local".
- Short zone labels are UTC offsets instead of abbreviations (`UTC-7`, not `PDT`). The selector shows the offset on each option and the selected value, and searches by it.
- Links from charts and tables to Search and other dashboards carry `tz`. External links don't.

The override isn't saved with saved searches or dashboards.

### Screenshots or video

<img width="529" height="243" alt="Screenshot 2026-10-30 at 10 39 50" src="https://github.com/user-attachments/assets/5cab281b-441d-48f0-9ae9-74d2c51abad7" />


<img width="664" height="319" alt="Screenshot 2026-10-30 at 10 40 02" src="https://github.com/user-attachments/assets/1822d592-ab3a-4597-b84f-78ba141d5349" />


### How to test on Vercel preview

**Preview routes:** /search, /dashboards

**Steps:**

1. On /search, click the time picker input (`data-testid="time-picker-input"`), click the "Time zone" field (`data-testid="time-picker-time-zone-select"`), type "tokyo" and click "Asia/Tokyo".
2. Verify the badge (`data-testid="time-picker-time-zone"`) shows "UTC+9" and the URL contains `tz=Asia%2FTokyo`.
3. Open the time picker, click "Default" (`data-testid="time-picker-time-zone-default"`), and verify `tz` is no longer in the URL.
4. On /dashboards, open any dashboard, repeat step 1, and verify the badge shows "UTC+9".

### References

- Linear Issue: Closes HDX-5741
- Related PRs: #3445, #3447, #3449

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 617d98b1 Deployed Oct 23, 2026 by vercel[bot]
Preview – hyperdx-storybook — 617d98b1 Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants