Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/time-zone-override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': minor
---

feat: Pick a time zone for the search and dashboard pages from the time picker, overriding the time zone in User Preferences. The picker shows the zone it uses, and the choice is kept in the URL and in links from charts and tables
48 changes: 34 additions & 14 deletions packages/app/src/DBDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ import {
parseRelativeTimeQuery,
useDefaultTimeRange,
useNewTimeQuery,
useTimeRangeInputText,
} from './timeQuery';
import {
TimeZoneOverrideProvider,
useTimeZoneLinkParam,
} from './timeZoneOverride';
import { useConfirm } from './useConfirm';
import { useDisplayTimeZone } from './useDisplayTimeZone';
import { FormatTime } from './useFormatTime';
Expand Down Expand Up @@ -278,6 +283,7 @@ function HeatmapTile({
);
const containerRef = useRef<HTMLDivElement>(null);

const addTimeZone = useTimeZoneLinkParam();
const eventDeltasUrl = useMemo(() => {
// Search page event deltas only supports trace sources and distribution mode
if (
Expand All @@ -294,8 +300,8 @@ function HeatmapTile({
});
if (!url) return null;
const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}mode=delta`;
}, [source, mode, queriedConfig, dateRange]);
return addTimeZone(`${url}${separator}mode=delta`);
}, [source, mode, queriedConfig, dateRange, addTimeZone]);

const handleClick = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
Expand Down Expand Up @@ -540,9 +546,8 @@ const Tile = ({
// changing them does not propagate up to the dashboard.
const [fullscreenDateRange, setFullscreenDateRange] =
useState<[Date, Date]>(dateRange);
const [fullscreenInputValue, setFullscreenInputValue] = useState<string>(() =>
dateRangeToString(dateRange, timeZone),
);
const [fullscreenInputValue, setFullscreenInputValue] =
useTimeRangeInputText(fullscreenDateRange);
const [fullscreenGranularity, setFullscreenGranularity] = useState<
Granularity | 'auto' | undefined
>(() => (granularity as Granularity | undefined) ?? 'auto');
Expand All @@ -556,7 +561,7 @@ const Tile = ({
(granularity as Granularity | undefined) ?? 'auto',
);
setIsFullscreen(true);
}, [dateRange, granularity, timeZone]);
}, [dateRange, granularity, timeZone, setFullscreenInputValue]);

const handleFullscreenSearch = useCallback(
(value: string) => {
Expand Down Expand Up @@ -914,13 +919,15 @@ const Tile = ({
);
}, [sqlFilters, queriedConfig, source]);

const addTimeZone = useTimeZoneLinkParam();
const replaySearchUrl = useMemo(() => {
return buildDashboardReplaySearchUrl({
const url = buildDashboardReplaySearchUrl({
source,
config: queriedConfig,
dateRange,
});
}, [dateRange, queriedConfig, source]);
return url && addTimeZone(url);
}, [dateRange, queriedConfig, source, addTimeZone]);

const hoverToolbar = useMemo(() => {
if (readOnly) return null;
Expand Down Expand Up @@ -1311,13 +1318,15 @@ const Tile = ({
variant="default"
getRowSearchLink={
isBuilderChartConfig(effectiveQueriedConfig)
? row =>
buildTableRowSearchUrl({
? row => {
const url = buildTableRowSearchUrl({
Comment thread
karl-power marked this conversation as resolved.
Resolved
row,
source,
config: effectiveQueriedConfig,
dateRange: effectiveDateRange,
})
});
return url && addTimeZone(url);
}
: undefined
}
onFilter={onFilter}
Expand Down Expand Up @@ -1478,6 +1487,7 @@ const Tile = ({
);
},
[
addTimeZone,
hoverToolbar,
queriedConfig,
title,
Expand Down Expand Up @@ -3568,9 +3578,19 @@ function DBDashboardPageGuarded({
);
}

const DBDashboardPageDynamic = dynamic(async () => DBDashboardPageGuarded, {
ssr: false,
});
// Outside DBDashboardPageGuarded, which formats the saved range in the zone.
function DBDashboardPageWithTimeZone(props: { presetConfig?: Dashboard }) {
return (
<TimeZoneOverrideProvider>
<DBDashboardPageGuarded {...props} />
</TimeZoneOverrideProvider>
);
}

const DBDashboardPageDynamic = dynamic(
async () => DBDashboardPageWithTimeZone,
{ ssr: false },
);

// @ts-expect-error for getLayout
DBDashboardPageDynamic.getLayout = withAppNavForSurface('dashboard');
Expand Down
5 changes: 4 additions & 1 deletion packages/app/src/DBSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import {
useDefaultTimeRange,
useNewTimeQuery,
} from '@/timeQuery';
import { TimeZoneOverrideProvider } from '@/timeZoneOverride';
import {
formatDurationMs,
orderByAfterRemovingSelectItem,
Expand Down Expand Up @@ -1048,7 +1049,9 @@ export function DBSearchPage() {
search: getSavedSearchIdFromPath() ?? undefined,
}}
>
<DBSearchPageContent />
<TimeZoneOverrideProvider>
<DBSearchPageContent />
</TimeZoneOverrideProvider>
</QueryAttributionProvider>
);
}
Expand Down
18 changes: 12 additions & 6 deletions packages/app/src/UserPreferencesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Tooltip,
} from '@mantine/core';

import { TimeZoneSelect } from './components/TimeZoneSelect';
import { TimeZoneSelect, TimeZoneShortcuts } from './components/TimeZoneSelect';
import {
isContentFontSize,
OPTIONS_CONTENT_FONT_SIZE,
Expand Down Expand Up @@ -114,11 +114,17 @@ export const UserPreferencesModal = ({
label="Time zone"
description="Times are displayed and input in this zone."
>
<TimeZoneSelect
data-testid="time-zone-select"
value={userPreferences.timeZone}
onChange={timeZone => setUserPreference({ timeZone })}
/>
<Stack gap={4}>
<TimeZoneSelect
data-testid="time-zone-select"
value={userPreferences.timeZone}
onChange={timeZone => timeZone && setUserPreference({ timeZone })}
/>
<TimeZoneShortcuts
testIdPrefix="time-zone"
onSelect={timeZone => setUserPreference({ timeZone })}
/>
</Stack>
</SettingContainer>

<Divider label="Search results" labelPosition="left" mt="sm" />
Expand Down
19 changes: 19 additions & 0 deletions packages/app/src/__tests__/UserPreferencesModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ describe('UserPreferencesModal', () => {

expect(readStoredPreferences().timeZone).toBe('Etc/UTC');
});

it.each([
['time-zone-utc', 'Asia/Tokyo', 'Etc/UTC'],
['time-zone-local', 'Etc/UTC', 'local'],
])(
'stores the zone from the %s shortcut',
async (testId, stored, expected) => {
renderModal({ timeZone: stored });

await userEvent.click(screen.getByTestId(testId));

expect(readStoredPreferences().timeZone).toBe(expected);
},
);

it('has no Default shortcut, since this is the default', () => {
renderModal();
expect(screen.queryByTestId('time-zone-default')).toBeNull();
});
});

describe('Row click', () => {
Expand Down
71 changes: 55 additions & 16 deletions packages/app/src/__tests__/timeZone.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
formatTimeZoneName,
getSupportedTimeZones,
getTimeZoneOffsetLabel,
getTimeZonePreferenceLabel,
getTimeZoneRangeShortName,
getTimeZoneShortName,
isTimeZonePreference,
isValidTimeZone,
LOCAL_TIME_ZONE,
resolveTimeZonePreference,
Expand All @@ -24,19 +26,21 @@ describe('resolveTimeZonePreference', () => {
});
});

describe('getTimeZoneOffsetLabel', () => {
it('uses the offset in effect on the date', () => {
expect(
getTimeZoneOffsetLabel('America/Los_Angeles', new Date('2026-07-01Z')),
).toBe('UTC-07:00');
expect(
getTimeZoneOffsetLabel('America/Los_Angeles', new Date('2026-12-01Z')),
).toBe('UTC-08:00');
expect(getTimeZoneOffsetLabel('Asia/Kolkata')).toBe('UTC+05:30');
describe('isTimeZonePreference', () => {
it('accepts local and zones the browser knows', () => {
expect(isTimeZonePreference(LOCAL_TIME_ZONE)).toBe(true);
expect(isTimeZonePreference('Asia/Tokyo')).toBe(true);
expect(isTimeZonePreference('Mars/Olympus_Mons')).toBe(false);
});
});

it('labels UTC with a zero offset', () => {
expect(getTimeZoneOffsetLabel('Etc/UTC')).toBe('UTC+00:00');
describe('getTimeZonePreferenceLabel', () => {
it('names local, UTC and other zones', () => {
expect(getTimeZonePreferenceLabel(LOCAL_TIME_ZONE)).toBe('Local');
expect(getTimeZonePreferenceLabel('Etc/UTC')).toBe('UTC');
expect(getTimeZonePreferenceLabel('America/Los_Angeles')).toBe(
'America/Los Angeles',
);
});
});

Expand All @@ -58,16 +62,16 @@ describe('formatTimeZoneName', () => {
});

describe('getTimeZoneShortName', () => {
it('uses the abbreviation in effect on the date', () => {
it('uses the offset in effect on the date, not an abbreviation', () => {
expect(
getTimeZoneShortName('America/Los_Angeles', new Date('2026-07-01Z')),
).toBe('PDT');
).toBe('UTC-7');
expect(
getTimeZoneShortName('America/Los_Angeles', new Date('2026-12-01Z')),
).toBe('PST');
).toBe('UTC-8');
});

it('names UTC and labels zones without an abbreviation from UTC', () => {
it('names a zero offset UTC and keeps partial-hour offsets', () => {
expect(getTimeZoneShortName('Etc/UTC')).toBe('UTC');
expect(getTimeZoneShortName('Asia/Tokyo')).toBe('UTC+9');
expect(getTimeZoneShortName('Asia/Kolkata')).toBe('UTC+5:30');
Expand All @@ -79,3 +83,38 @@ describe('getTimeZoneShortName', () => {
);
});
});

describe('getTimeZoneRangeShortName', () => {
it('uses the offset during the range, not today', () => {
expect(
getTimeZoneRangeShortName('America/Los_Angeles', [
new Date('2026-01-15T10:00:00Z'),
new Date('2026-01-15T11:00:00Z'),
]),
).toBe('UTC-8');
});

it('shows both offsets for a range across a DST change', () => {
expect(
getTimeZoneRangeShortName('America/Los_Angeles', [
new Date('2026-10-31T12:00:00Z'),
new Date('2026-11-02T12:00:00Z'),
]),
).toBe('UTC-7/-8');
expect(
getTimeZoneRangeShortName('Europe/London', [
new Date('2026-03-28T12:00:00Z'),
new Date('2026-03-30T12:00:00Z'),
]),
).toBe('UTC+0/+1');
});

it('shows one offset for a zone without DST', () => {
expect(
getTimeZoneRangeShortName('Etc/UTC', [
new Date('2026-01-15Z'),
new Date('2026-07-15Z'),
]),
).toBe('UTC');
});
});
Loading
Loading