Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(dates): resolve calendar-relative dates at local midnight across DST (#109167)

Daniel Visca16def832bd77
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index c08a565c1cbb..41c3f1f6635f 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -10451,7 +10451,7 @@ snapshots:
scenes-app-inbox-scene--installing-self-driving--light:
hash: v1.k794b7964.fc1d6c0f35936c2a9a59fe89dbc9fdd8bae321ef4a4cba09af26626522d606eb.Ben1AjqSzgVvRph3ykOT3OusF-gZBfMIiFyONV4k6hA
scenes-app-inbox-scene--legacy--dark:
- hash: v1.k794b7964.cf7ea7c47bba3a13402d4ffca0936c08040dee5c57ddf01bf8cee89892eb2664.dShBZ3vzzVmp5DadPnsR_vMHw11m5cA6LVA9A2eFOzE
+ hash: v1.k794b7964.58139c66f4babe4a452840859892fcfd58bef31532765cd230177526af1a9219.QfsY_Gl8moPOAD0zO3aIlZNOsI4oCDKcnC42a4fv13s
scenes-app-inbox-scene--legacy--light:
hash: v1.k794b7964.f503449990502057e4a2bf6d41dd2c94efad321503856eb11d338084507ed4fb.USiZ5UnWiaNkNJ1ci9aMi6h82TyPLJ1ASTwGfBmidj4
scenes-app-inbox-scene--legacy-report--dark:
diff --git a/frontend/src/lib/utils/dateFilters.test.ts b/frontend/src/lib/utils/dateFilters.test.ts
index c5ff6c582cb4..720ae48ee90f 100644
--- a/frontend/src/lib/utils/dateFilters.test.ts
+++ b/frontend/src/lib/utils/dateFilters.test.ts
@@ -224,6 +224,19 @@ describe('dateFilters utils', () => {
tk.reset()
})
+ // A window across a daylight saving change must start at local midnight, like the backend's
+ // relative_date_parse, and not keep the UTC offset of today.
+ it.each([
+ ['Europe/Zurich', '2026-03-31T10:00:00Z', '-7d', '2026-03-23T23:00:00.000Z'],
+ ['Europe/Zurich', '2026-10-27T10:00:00Z', '-7d', '2026-10-19T22:00:00.000Z'],
+ ['Europe/Zurich', '2026-04-15T10:00:00Z', '-1m', '2026-03-14T23:00:00.000Z'],
+ ['America/New_York', '2026-03-10T12:00:00Z', '-1w', '2026-03-03T05:00:00.000Z'],
+ ['Europe/Zurich', '2026-03-29T01:30:00Z', '-1h', '2026-03-29T00:30:00.000Z'],
+ ])('resolves %s %s %s across a daylight saving change', (timezone, now, date, expected) => {
+ tk.freeze(new Date(now))
+ expect(dateStringToDayJs(date, timezone)?.toISOString()).toEqual(expected)
+ })
+
it('handles various dates', () => {
expect(dateStringToDayJs('2022-02-22')?.utc(true).toISOString()).toEqual('2022-02-22T00:00:00.000Z')
expect(dateStringToDayJs('1999-12-31')?.utc(true).toISOString()).toEqual('1999-12-31T00:00:00.000Z')
diff --git a/frontend/src/lib/utils/dateFilters.ts b/frontend/src/lib/utils/dateFilters.ts
index 0784f8684c40..cc924118fe0a 100644
--- a/frontend/src/lib/utils/dateFilters.ts
+++ b/frontend/src/lib/utils/dateFilters.ts
@@ -338,7 +338,8 @@ export function dateStringToDayJs(date: string | null, timezone: string = 'UTC')
const isSubDay = ['hour', 'minute', 'second'].includes(dateComponents.unit)
const offset: dayjs.Dayjs = isSubDay ? dayjs().tz(timezone) : dayjs().tz(timezone).startOf('day')
const response = componentsToDayJs(dateComponents, offset, timezone)
- return response
+ // dayjs keeps today's UTC offset when it adds calendar units, so resolve the local time again.
+ return isSubDay ? response : response.tz(timezone, true)
}
export function isValidRelativeOrAbsoluteDate(date: string): boolean {