: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogvm): resolve ambiguous dates independently of the clock (#126995)
posthog[bot]db6edbc4ae95
diff --git a/common/hogvm/typescript/src/__tests__/date.test.ts b/common/hogvm/typescript/src/__tests__/date.test.tsindex 85b73bc8968f..a804cef0bcdc 100644--- a/common/hogvm/typescript/src/__tests__/date.test.ts+++ b/common/hogvm/typescript/src/__tests__/date.test.ts@@ -111,9 +111,17 @@ describe('date-like string grammar', () => {expect(toDateTime(input as any)).toBeNull()})- test('an ambiguous local time takes the first of the DST fold', () => {- // 01:30 happens twice on 2024-11-03 in New York; Rust's `LocalResult::Ambiguous(dt, _)` and- // luxon take the first (-04:00). Pinned because pytz's `localize` defaults to the second.- expect(toUnixTimestamp('2024-11-03 01:30:00', 'America/New_York')).toBe(1730611800)- })+ test.each(['2026-07-01T12:00:00Z', '2026-12-01T12:00:00Z'])(+ 'an ambiguous local time takes the first of the DST fold when now is %s',+ (now) => {+ jest.useFakeTimers().setSystemTime(new Date(now))+ try {+ expect(toUnixTimestamp('2024-11-03 01:30:00', 'America/New_York')).toBe(1730611800)+ expect(toDateTime('2024-11-03 01:30:00', 'America/New_York')!.dt).toBe(1730611800)+ expect(toUnixTimestamp('2024-11-03T01:30:00-05:00', 'America/New_York')).toBe(1730615400)+ } finally {+ jest.useRealTimers()+ }+ }+ )})diff --git a/common/hogvm/typescript/src/stl/date.ts b/common/hogvm/typescript/src/stl/date.tsindex f25859522bd6..5cb4642b092e 100644--- a/common/hogvm/typescript/src/stl/date.ts+++ b/common/hogvm/typescript/src/stl/date.ts@@ -119,7 +119,11 @@ export function parseDateLike(input: string, zone?: string): DateTime | null {// Normalize to strict ISO so luxon's parser accepts it: `T` separator, uppercase `Z`.const time = hourMinute ? `T${hourMinute}${second ? `:${second}${millis}` : ''}${offset?.toUpperCase() ?? ''}` : ''const dt = DateTime.fromISO(`${year}${monthDay}${time}`, { zone: zone || 'UTC' })- return dt.isValid ? dt : null+ if (!dt.isValid) {+ return null+ }+ // Luxon's default fold choice depends on the current offset. Match the other VMs' earlier instant.+ return offset ? dt : DateTime.min(...dt.getPossibleOffsets())}// NOTE: `toUnixTimestamp` keeps each VM's own failure mode for unparseable input. Here it is an