: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(workflows): use real moments when comparing recurrence occurrences to now (#67022)
Daniel Marchukeef54c8baace
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/rrule-helpers.test.ts b/products/workflows/frontend/Workflows/hogflows/steps/components/rrule-helpers.test.tsindex e2618f7f40ed..b8801e8b482e 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/components/rrule-helpers.test.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/rrule-helpers.test.ts@@ -244,6 +244,31 @@ describe('rrule-helpers', () => {expect(d.getTime()).toBeGreaterThan(Date.now())}})++ describe("keeps today's still-pending occurrence across a timezone offset", () => {+ afterEach(() => {+ jest.useRealTimers()+ })++ // now=12:26 UTC; today's 9 AM Toronto occurrence is 13:00 UTC (~34 min away).+ // The occurrence's fake-UTC value (09:00) is "before" now in raw UTC terms, so a+ // naive comparison drops it — the real moment must be used instead.+ it('includes the occurrence later today rather than skipping to tomorrow', () => {+ jest.useFakeTimers().setSystemTime(new Date('2026-06-30T12:26:00Z'))+ const state: ScheduleState = {+ ...DEFAULT_STATE,+ frequency: 'weekly',+ weekdays: [0, 1, 2, 3, 4], // Mon–Fri+ endType: 'never',+ }+ // 9 AM America/Toronto (EDT, UTC-4) on Mon June 22 2026 == 13:00 UTC+ const result = computePreviewOccurrences(state, '2026-06-22T13:00:00Z', 'America/Toronto')++ // First occurrence must be Tue June 30 (still pending today), not Wed July 1+ const first = fakeUtcToReal(result[0], 'America/Toronto')+ expect(first.tz('America/Toronto').format('YYYY-MM-DD HH:mm')).toBe('2026-06-30 09:00')+ })+ })})describe('fakeUtcToReal', () => {diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/rrule-helpers.ts b/products/workflows/frontend/Workflows/hogflows/steps/components/rrule-helpers.tsindex 09eb079cf0f8..730a4e7578f4 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/components/rrule-helpers.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/rrule-helpers.ts@@ -212,10 +212,13 @@ export function computePreviewOccurrences(const rule = new RRule(options as ConstructorParameters<typeof RRule>[0])const isFinite = state.endType !== 'never'- if (dayjs(dtstart).isBefore(dayjs())) {+ // Occurrences are "fake UTC" (their UTC fields encode local time in the schedule+ // timezone), so convert each to a real moment before comparing against now —+ // otherwise an occurrence still pending today is wrongly treated as already past.+ const now = dayjs()+ if (fakeUtcToReal(dtstart, timezone).isBefore(now)) {const all = rule.all((_, i) => i < (isFinite ? MAX_PREVIEW_COUNT : limit * 50))- const now = new Date()- const future = all.filter((d) => d.getTime() > now.getTime())+ const future = all.filter((d) => fakeUtcToReal(d, timezone).isAfter(now))return isFinite ? future : future.slice(0, limit)}return rule.all((_, i) => i < (isFinite ? MAX_PREVIEW_COUNT : limit))