Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Resolve Alberta, Manitoba and BC time zones consistently across engines (#3396)

Luke Vella1ff24da46fb4
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
index 0b6dca2a1..311f1c260 100644
--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
@@ -13,22 +13,24 @@ import { useUpdatePollMutation } from "@/features/poll/components/mutations";
import { usePoll } from "@/features/poll/components/poll-context";
import { filterParticipantsByVote } from "@/features/poll/utils";
import { Trans, useTranslation } from "@/i18n/client";
+import { resolveTimeZone } from "@/lib/datetime/time-zone-overrides";
import { dayjs } from "@/lib/dayjs";
import {
encodeDateOption,
getBrowserTimeZone,
} from "@/lib/utils/date-time-utils";
+const toPollWallTime = (
+ value: ReturnType<typeof dayjs>,
+ timeZone: string | null,
+) =>
+ timeZone ? value.tz(resolveTimeZone(timeZone, value.toDate())) : value.utc();
+
const convertOptionToString = (
option: { startTime: Date; duration: number },
timeZone: string | null,
) => {
- let start = dayjs(option.startTime);
- if (timeZone) {
- start = start.tz(timeZone);
- } else {
- start = start.utc();
- }
+ const start = toPollWallTime(dayjs(option.startTime), timeZone);
return option.duration === 0
? start.format("YYYY-MM-DD")
: `${start.format("YYYY-MM-DDTHH:mm:ss")}/${start
@@ -53,25 +55,17 @@ const Page = () => {
router.push(pollLink);
};
- let firstDate = dayjs(poll.options[0]?.startTime);
-
- if (poll.timeZone) {
- firstDate = firstDate.tz(poll.timeZone);
- } else {
- firstDate = firstDate.utc();
- }
+ const firstDate = toPollWallTime(
+ dayjs(poll.options[0]?.startTime),
+ poll.timeZone,
+ );
const form = useForm({
defaultValues: {
navigationDate: firstDate.format("YYYY-MM-DD"),
view: "month" as const,
options: poll.options.map((option) => {
- let start = dayjs(option.startTime);
- if (poll.timeZone) {
- start = start.tz(poll.timeZone);
- } else {
- start = start.utc();
- }
+ const start = toPollWallTime(dayjs(option.startTime), poll.timeZone);
return option.duration > 0
? {
type: "timeSlot" as const,
diff --git a/apps/web/src/lib/datetime/format.test.ts b/apps/web/src/lib/datetime/format.test.ts
index ea3f9fe0b..1635841df 100644
--- a/apps/web/src/lib/datetime/format.test.ts
+++ b/apps/web/src/lib/datetime/format.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import {
formatDate,
+ formatDateParts,
formatDateTime,
formatDateTimeRange,
formatRelativeTime,
@@ -173,3 +174,70 @@ describe("formatRelativeTime", () => {
expect(formatRelativeTime(twoHoursAgo(), "de")).toBe("vor 2 Stunden");
});
});
+
+// Alberta, Manitoba and British Columbia stopped falling back on 2026-11-01.
+// These must hold on engines whose tz data predates the change.
+describe("provinces that stopped changing clocks", () => {
+ const time = (instant: string, timeZone: string) =>
+ formatDateTime(new Date(instant), {
+ preset: "time",
+ ...ctx("en", "hours24", timeZone),
+ });
+
+ it("formats Alberta times at UTC-6 after the cutoff", () => {
+ expect(time("2026-11-05T16:00:00Z", "America/Edmonton")).toBe("10:00");
+ });
+
+ it("formats Manitoba times at UTC-5 after the cutoff", () => {
+ expect(time("2026-11-05T15:00:00Z", "America/Winnipeg")).toBe("10:00");
+ });
+
+ it("formats British Columbia times at UTC-7 after the cutoff", () => {
+ expect(time("2026-11-05T17:00:00Z", "America/Vancouver")).toBe("10:00");
+ });
+
+ it("formats ranges after the cutoff", () => {
+ const out = formatDateTimeRange(
+ new Date("2026-11-05T16:00:00Z"),
+ new Date("2026-11-05T17:00:00Z"),
+ { preset: "time", ...ctx("en", "hours24", "America/Edmonton") },
+ );
+ expect(out).toContain("10:00");
+ expect(out).toContain("11:00");
+ });
+
+ it("formats a range that crosses the cutoff", () => {
+ // 01:30 MDT to 02:30 at UTC-6; the old rules put the end at 01:30 MST.
+ const out = formatDateTimeRange(
+ new Date("2026-11-01T07:30:00Z"),
+ new Date("2026-11-01T08:30:00Z"),
+ { preset: "time", ...ctx("en", "hours24", "America/Edmonton") },
+ );
+ expect(out).toContain("01:30");
+ expect(out).toContain("02:30");
+ });
+
+ it("formats a range whose endpoints need different offsets", () => {
+ // 10:00 at UTC-7 in January, 10:00 at UTC-6 in November.
+ const out = formatDateTimeRange(
+ new Date("2026-01-15T17:00:00Z"),
+ new Date("2026-11-05T16:00:00Z"),
+ { preset: "datetime", ...ctx("en", "hours24", "America/Edmonton") },
+ );
+ expect(out).toContain("Jan 15, 2026, 10:00");
+ expect(out).toContain("Nov 5, 2026, 10:00");
+ });
+
+ it("formats date parts on the right calendar day after the cutoff", () => {
+ expect(
+ formatDateParts(new Date("2026-11-06T06:30:00Z"), {
+ locale: "en",
+ timeZone: "America/Edmonton",
+ }).day,
+ ).toBe("6");
+ });
+
+ it("leaves times before the cutoff unchanged", () => {
+ expect(time("2026-07-01T16:00:00Z", "America/Edmonton")).toBe("10:00");
+ });
+});
diff --git a/apps/web/src/lib/datetime/format.ts b/apps/web/src/lib/datetime/format.ts
index fa079eb94..f6719bd77 100644
--- a/apps/web/src/lib/datetime/format.ts
+++ b/apps/web/src/lib/datetime/format.ts
@@ -1,3 +1,4 @@
+import { resolveTimeZone } from "@/lib/datetime/time-zone-overrides";
import type { DateInput, TimeFormat } from "@/lib/datetime/types";
export type DatePreset =
@@ -23,6 +24,10 @@ function toDate(value: DateInput): Date {
return value instanceof Date ? value : new Date(value);
}
+function resolveOptionalTimeZone(timeZone: string | undefined, date: Date) {
+ return timeZone ? resolveTimeZone(timeZone, date) : timeZone;
+}
+
const formatters = new Map<string, Intl.DateTimeFormat>();
function getCachedIntlDateFormatter({
@@ -109,7 +114,11 @@ export function formatDateTime(
value: DateInput,
options: FormatDateTimeOptions,
): string {
- return getCachedIntlDateFormatter(options).format(toDate(value));
+ const date = toDate(value);
+ return getCachedIntlDateFormatter({
+ ...options,
+ timeZone: resolveOptionalTimeZone(options.timeZone, date),
+ }).format(date);
}
export function formatDateTimeRange(
@@ -117,10 +126,24 @@ export function formatDateTimeRange(
end: DateInput,
options: FormatDateTimeOptions,
): string {
- return getCachedIntlDateFormatter(options).formatRange(
- toDate(start),
- toDate(end),
- );
+ const startDate = toDate(start);
+ const endDate = toDate(end);
+ const startTimeZone = resolveOptionalTimeZone(options.timeZone, startDate);
+ const endTimeZone = resolveOptionalTimeZone(options.timeZone, endDate);
+ const formatter = getCachedIntlDateFormatter({
+ ...options,
+ timeZone: startTimeZone,
+ });
+ if (startTimeZone === endTimeZone) {
+ return formatter.formatRange(startDate, endDate);
+ }
+ // Only a range crossing an override cutoff lands here; no single zone
+ // formats both ends correctly, so each end gets its own.
+ const endFormatter = getCachedIntlDateFormatter({
+ ...options,
+ timeZone: endTimeZone,
+ });
+ return `${formatter.format(startDate)} – ${endFormatter.format(endDate)}`;
}
// All-day values are stored as UTC midnight, so they always format in UTC.
@@ -153,7 +176,9 @@ export function formatDateParts(
value: DateInput,
options: { locale: string; timeZone?: string },
): DateParts {
- const key = `${options.locale}|${options.timeZone ?? ""}`;
+ const date = toDate(value);
+ const timeZone = resolveOptionalTimeZone(options.timeZone, date);
+ const key = `${options.locale}|${timeZone ?? ""}`;
let f = partsFormatters.get(key);
if (!f) {
f = new Intl.DateTimeFormat(options.locale, {
@@ -162,13 +187,13 @@ export function formatDateParts(
month: "short",
year: "numeric",
// An empty string is an invalid IANA zone and throws; treat it as "unset".
- timeZone: options.timeZone || undefined,
+ timeZone: timeZone || undefined,
});
partsFormatters.set(key, f);
}
const parts: DateParts = { weekday: "", day: "", month: "", year: "" };
- for (const part of f.formatToParts(toDate(value))) {
+ for (const part of f.formatToParts(date)) {
if (part.type in parts) {
parts[part.type as keyof DateParts] = part.value;
}
diff --git a/apps/web/src/lib/datetime/slot-generator.test.ts b/apps/web/src/lib/datetime/slot-generator.test.ts
index ef6549507..873e6f03a 100644
--- a/apps/web/src/lib/datetime/slot-generator.test.ts
+++ b/apps/web/src/lib/datetime/slot-generator.test.ts
@@ -315,4 +315,44 @@ describe("time-slots utilities", () => {
});
});
});
+
+ // Alberta, Manitoba and British Columbia stopped falling back on 2026-11-01.
+ // These must hold on engines whose tz data predates the change.
+ describe("provinces that stopped changing clocks", () => {
+ it("parses Alberta wall times at UTC-6 after the cutoff", () => {
+ expect(
+ parseStartTime("2026-11-05T10:00:00", "America/Edmonton", 60).startTime,
+ ).toEqual(new Date("2026-11-05T16:00:00Z"));
+ });
+
+ it("parses Manitoba wall times at UTC-5 after the cutoff", () => {
+ expect(
+ parseStartTime("2026-11-05T10:00:00", "America/Winnipeg", 60).startTime,
+ ).toEqual(new Date("2026-11-05T15:00:00Z"));
+ });
+
+ it("parses British Columbia wall times at UTC-7 after the cutoff", () => {
+ expect(
+ parseStartTime("2026-11-05T10:00:00", "America/Vancouver", 60)
+ .startTime,
+ ).toEqual(new Date("2026-11-05T17:00:00Z"));
+ });
+
+ it("generates Alberta slots at UTC-6 after the cutoff", () => {
+ const slots = generateTimeSlots(
+ {
+ startDate: "2026-11-05",
+ endDate: "2026-11-05",
+ daysOfWeek: ["thu"],
+ fromTime: "10:00",
+ toTime: "11:00",
+ },
+ "America/Edmonton",
+ 60,
+ );
+ expect(slots.map((slot) => slot.startTime)).toEqual([
+ new Date("2026-11-05T16:00:00Z"),
+ ]);
+ });
+ });
});
diff --git a/apps/web/src/lib/datetime/slot-generator.ts b/apps/web/src/lib/datetime/slot-generator.ts
index 2eb159abb..c86b4ddab 100644
--- a/apps/web/src/lib/datetime/slot-generator.ts
+++ b/apps/web/src/lib/datetime/slot-generator.ts
@@ -1,3 +1,4 @@
+import { resolveTimeZoneAtWallTime } from "@/lib/datetime/time-zone-overrides";
import { dayjs } from "@/lib/dayjs";
export type SlotGeneratorInput = {
@@ -29,7 +30,7 @@ const parseDateTimeInTimeZone = (value: string, timeZone?: string) =>
hasTzOffset(value)
? dayjs(value)
: timeZone
- ? dayjs(value).tz(timeZone, true)
+ ? dayjs(value).tz(resolveTimeZoneAtWallTime(timeZone, value), true)
: dayjs(value).utc(true);
const parseLocalDateTimeInTimeZone = (
@@ -38,7 +39,10 @@ const parseLocalDateTimeInTimeZone = (
timeZone: string | undefined,
) =>
timeZone
- ? dayjs(`${date}T${time}`).tz(timeZone, true)
+ ? dayjs(`${date}T${time}`).tz(
+ resolveTimeZoneAtWallTime(timeZone, `${date}T${time}`),
+ true,
+ )
: dayjs(`${date}T${time}`).utc(true);
export const parseStartTime = (
@@ -88,9 +92,9 @@ export const generateTimeSlots = (
}
daysVisited++;
const date = cursor.format("YYYY-MM-DD");
- // Get day of week in the target timezone
- const dayInTz = timeZone ? dayjs.tz(date, timeZone).day() : cursor.day();
- if (!allowed.has(dayInTz)) {
+ // The cursor's UTC date is the calendar date itself, so its weekday is
+ // the same in every zone.
+ if (!allowed.has(cursor.day())) {
continue;
}
const windowStart = parseLocalDateTimeInTimeZone(
diff --git a/apps/web/src/lib/datetime/time-zone-overrides.test.ts b/apps/web/src/lib/datetime/time-zone-overrides.test.ts
new file mode 100644
index 000000000..9e03518e6
--- /dev/null
+++ b/apps/web/src/lib/datetime/time-zone-overrides.test.ts
@@ -0,0 +1,122 @@
+import { describe, expect, it } from "vitest";
+import {
+ resolveTimeZone,
+ resolveTimeZoneAtWallTime,
+ timeZoneOverrides,
+} from "./time-zone-overrides";
+
+const offsetMinutesAt = (timeZone: string, instant: Date) => {
+ const parts = new Intl.DateTimeFormat("en-US", {
+ timeZone,
+ hourCycle: "h23",
+ year: "numeric",
+ month: "2-digit",
+ day: "2-digit",
+ hour: "2-digit",
+ minute: "2-digit",
+ }).formatToParts(instant);
+ const get = (type: Intl.DateTimeFormatPartTypes) =>
+ Number(parts.find((part) => part.type === type)?.value);
+ const wall = Date.UTC(
+ get("year"),
+ get("month") - 1,
+ get("day"),
+ get("hour"),
+ get("minute"),
+ );
+ return (wall - instant.getTime()) / 60_000;
+};
+
+describe("resolveTimeZone", () => {
+ it("substitutes Alberta's zone after its last fall back", () => {
+ expect(
+ resolveTimeZone("America/Edmonton", new Date("2026-11-05T16:00:00Z")),
+ ).toBe("America/Regina");
+ });
+
+ it("substitutes Manitoba's zone after its last fall back", () => {
+ expect(
+ resolveTimeZone("America/Winnipeg", new Date("2026-11-05T15:00:00Z")),
+ ).toBe("America/Cancun");
+ });
+
+ it("substitutes British Columbia's zone after its last fall back", () => {
+ expect(
+ resolveTimeZone("America/Vancouver", new Date("2026-11-05T17:00:00Z")),
+ ).toBe("America/Phoenix");
+ });
+
+ it("keeps the zone before the cutoff", () => {
+ expect(
+ resolveTimeZone("America/Edmonton", new Date("2026-11-01T07:59:00Z")),
+ ).toBe("America/Edmonton");
+ });
+
+ it("covers legacy aliases", () => {
+ const instant = new Date("2026-11-05T16:00:00Z");
+ expect(resolveTimeZone("Canada/Mountain", instant)).toBe("America/Regina");
+ expect(resolveTimeZone("Canada/Central", instant)).toBe("America/Cancun");
+ expect(resolveTimeZone("Canada/Pacific", instant)).toBe("America/Phoenix");
+ });
+
+ it("leaves other zones alone", () => {
+ expect(
+ resolveTimeZone("America/Denver", new Date("2026-11-05T16:00:00Z")),
+ ).toBe("America/Denver");
+ });
+});
+
+describe("resolveTimeZoneAtWallTime", () => {
+ it("substitutes wall times from the cutoff onwards", () => {
+ expect(
+ resolveTimeZoneAtWallTime("America/Edmonton", "2026-11-01T02:00:00"),
+ ).toBe("America/Regina");
+ expect(
+ resolveTimeZoneAtWallTime("America/Edmonton", "2026-11-05T10:00"),
+ ).toBe("America/Regina");
+ expect(
+ resolveTimeZoneAtWallTime("America/Edmonton", "2026-11-05 10:00:00"),
+ ).toBe("America/Regina");
+ });
+
+ it("keeps the zone for wall times before the cutoff", () => {
+ expect(
+ resolveTimeZoneAtWallTime("America/Edmonton", "2026-11-01T01:59:00"),
+ ).toBe("America/Edmonton");
+ expect(resolveTimeZoneAtWallTime("America/Edmonton", "2026-11-01")).toBe(
+ "America/Edmonton",
+ );
+ });
+
+ it("leaves unparseable values and other zones alone", () => {
+ expect(resolveTimeZoneAtWallTime("America/Edmonton", "garbage")).toBe(
+ "America/Edmonton",
+ );
+ expect(
+ resolveTimeZoneAtWallTime("America/Denver", "2026-11-05T10:00:00"),
+ ).toBe("America/Denver");
+ });
+});
+
+describe.each(timeZoneOverrides)("override for $zones.0", (override) => {
+ it("uses a substitute with the declared fixed offset", () => {
+ for (const instant of ["2026-12-15T12:00:00Z", "2027-07-15T12:00:00Z"]) {
+ expect(offsetMinutesAt(override.substitute, new Date(instant))).toBe(
+ override.utcOffsetMinutes,
+ );
+ }
+ });
+
+ it("matches the original zone just before the cutoff", () => {
+ const justBefore = new Date(
+ resolveCutoff(override.from, override.utcOffsetMinutes) - 60_000,
+ );
+ for (const zone of override.zones) {
+ expect(offsetMinutesAt(zone, justBefore)).toBe(override.utcOffsetMinutes);
+ }
+ });
+});
+
+function resolveCutoff(from: string, utcOffsetMinutes: number) {
+ return Date.parse(`${from}:00Z`) - utcOffsetMinutes * 60_000;
+}
diff --git a/apps/web/src/lib/datetime/time-zone-overrides.ts b/apps/web/src/lib/datetime/time-zone-overrides.ts
new file mode 100644
index 000000000..6fb4524fb
--- /dev/null
+++ b/apps/web/src/lib/datetime/time-zone-overrides.ts
@@ -0,0 +1,93 @@
+/**
+ * Zones whose rules changed recently enough that engines disagree about them.
+ *
+ * Every Intl call reads the tz data bundled with its engine, and Rallly
+ * converts on both the server (Node) and the viewer's browser. When one has
+ * the new rules and the other doesn't, times shift by an hour. From `from`
+ * (local wall time) onwards, each zone is swapped for a substitute that every
+ * engine agrees has the zone's new fixed offset. The substitute matches the
+ * old zone just before the cutoff and the corrected rules after it, so the
+ * swap is seamless and harmless once every engine has caught up.
+ *
+ * Remove an entry once engines with the IANA fix have been out for a year.
+ */
+export const timeZoneOverrides = [
+ {
+ // Alberta: permanent UTC-6 from its 2026-03-08 spring forward (IANA 2026c).
+ // The Northwest Territories followed (IANA 2026d).
+ zones: [
+ "America/Edmonton",
+ "America/Yellowknife",
+ "America/Inuvik",
+ "Canada/Mountain",
+ ],
+ from: "2026-11-01T02:00",
+ substitute: "America/Regina",
+ utcOffsetMinutes: -360,
+ },
+ {
+ // Manitoba: permanent UTC-5, announced 2026-09-17, not yet in any IANA
+ // release.
+ zones: ["America/Winnipeg", "Canada/Central"],
+ from: "2026-11-01T02:00",
+ substitute: "America/Cancun",
+ utcOffsetMinutes: -300,
+ },
+ {
+ // British Columbia: permanent UTC-7 (IANA 2026b).
+ zones: ["America/Vancouver", "Canada/Pacific"],
+ from: "2026-11-01T02:00",
+ substitute: "America/Phoenix",
+ utcOffsetMinutes: -420,
+ },
+] as const;
+
+const overridesByZone = new Map(
+ timeZoneOverrides.flatMap((override) => {
+ // Wall-clock fields encoded as if they were UTC, for ordering only.
+ const fromWallTime = Date.parse(`${override.from}:00Z`);
+ const resolved = {
+ substitute: override.substitute,
+ fromWallTime,
+ fromInstant: fromWallTime - override.utcOffsetMinutes * 60_000,
+ };
+ return override.zones.map((zone) => [zone as string, resolved] as const);
+ }),
+);
+
+const wallTimePattern = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2}))?/;
+
+function parseWallTime(value: string) {
+ const match = wallTimePattern.exec(value);
+ if (!match) {
+ return undefined;
+ }
+ const [, year, month, day, hour = "0", minute = "0"] = match;
+ return Date.UTC(
+ Number(year),
+ Number(month) - 1,
+ Number(day),
+ Number(hour),
+ Number(minute),
+ );
+}
+
+/** The zone to hand to Intl or dayjs when converting this instant. */
+export function resolveTimeZone(timeZone: string, instant: Date) {
+ const override = overridesByZone.get(timeZone);
+ return override && instant.getTime() >= override.fromInstant
+ ? override.substitute
+ : timeZone;
+}
+
+/**
+ * The zone to use when turning a wall-clock time (YYYY-MM-DDTHH:mm, with no
+ * offset) into an instant.
+ */
+export function resolveTimeZoneAtWallTime(timeZone: string, wallTime: string) {
+ const override = overridesByZone.get(timeZone);
+ const wall = override ? parseWallTime(wallTime) : undefined;
+ return override && wall !== undefined && wall >= override.fromWallTime
+ ? override.substitute
+ : timeZone;
+}
diff --git a/apps/web/src/lib/datetime/utils.test.ts b/apps/web/src/lib/datetime/utils.test.ts
index 356606b0f..fb653eeea 100644
--- a/apps/web/src/lib/datetime/utils.test.ts
+++ b/apps/web/src/lib/datetime/utils.test.ts
@@ -63,6 +63,15 @@ describe("getCalendarDate", () => {
});
});
+describe("getCalendarDate in provinces that stopped changing clocks", () => {
+ it("uses Alberta's UTC-6 after the cutoff", () => {
+ // 00:30 on Nov 6 at UTC-6; still Nov 5 under the old UTC-7 rule.
+ expect(
+ getCalendarDate(new Date("2026-11-06T06:30:00Z"), "America/Edmonton"),
+ ).toBe("2026-11-06");
+ });
+});
+
describe("calendarDateToUTCMidnight", () => {
it("encodes a calendar date as UTC midnight", () => {
expect(calendarDateToUTCMidnight("2025-07-01").toISOString()).toBe(
diff --git a/apps/web/src/lib/datetime/utils.ts b/apps/web/src/lib/datetime/utils.ts
index c65363571..75c0b0dc7 100644
--- a/apps/web/src/lib/datetime/utils.ts
+++ b/apps/web/src/lib/datetime/utils.ts
@@ -1,3 +1,4 @@
+import { resolveTimeZone } from "@/lib/datetime/time-zone-overrides";
import type { DateInput, TimeFormat } from "@/lib/datetime/types";
function toDate(value: DateInput) {
@@ -20,7 +21,7 @@ export function toISODate(value: DateInput) {
*/
export function getCalendarDate(now: Date, timeZone: string): string {
const parts = new Intl.DateTimeFormat("en-CA", {
- timeZone,
+ timeZone: resolveTimeZone(timeZone, now),
year: "numeric",
month: "2-digit",
day: "2-digit",
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index 068bec2c3..c98609a19 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -39,6 +39,7 @@ import {
isSpaceBrandingActive,
} from "@/features/space/utils";
import { scheduleWebhookDispatch } from "@/features/webhook/mutations";
+import { resolveTimeZoneAtWallTime } from "@/lib/datetime/time-zone-overrides";
import { dayjs } from "@/lib/dayjs";
import { AppError } from "@/lib/errors/app-error";
import { identifyGroup, track } from "@/lib/posthog";
@@ -267,7 +268,9 @@ export const polls = router({
const optionsData = input.options.map((option) => ({
startTime:
timeZone && option.endDate
- ? dayjs(option.startDate).tz(timeZone, true).toDate()
+ ? dayjs(option.startDate)
+ .tz(resolveTimeZoneAtWallTime(timeZone, option.startDate), true)
+ .toDate()
: dayjs(option.startDate).utc(true).toDate(),
duration: option.endDate
? dayjs(option.endDate).diff(dayjs(option.startDate), "minute")
@@ -462,7 +465,12 @@ export const polls = router({
if (end) {
return {
startTime: input.timeZone
- ? dayjs(start).tz(input.timeZone, true).toDate()
+ ? dayjs(start)
+ .tz(
+ resolveTimeZoneAtWallTime(input.timeZone, start),
+ true,
+ )
+ .toDate()
: dayjs(start).utc(true).toDate(),
duration: dayjs(end).diff(dayjs(start), "minute"),
pollId,
diff --git a/biome-plugins/no-unresolved-dayjs-tz.grit b/biome-plugins/no-unresolved-dayjs-tz.grit
new file mode 100644
index 000000000..de2a7ab21
--- /dev/null
+++ b/biome-plugins/no-unresolved-dayjs-tz.grit
@@ -0,0 +1,22 @@
+// dayjs converts with the engine's own tz data, which lags recent rule
+// changes (Alberta, Manitoba, British Columbia in 2026). Route the zone
+// through `@/lib/datetime/time-zone-overrides` so server and browser agree.
+language js
+
+or {
+ `$obj.tz($zone, $keepLocalTime)` as $match,
+ `$obj.tz($zone)` as $match
+} where {
+ $zone <: not or {
+ `resolveTimeZone($zoneId, $instant)`,
+ `resolveTimeZoneAtWallTime($zoneId, $wallTime)`
+ },
+ $filename <: not or {
+ r".*\.test\.tsx?",
+ r".*/tests/.*",
+ r".*/scripts/.*",
+ r".*/packages/.*",
+ r".*/apps/landing/.*"
+ },
+ register_diagnostic(span=$match, message="Pass the zone through `resolveTimeZone` or `resolveTimeZoneAtWallTime` from `@/lib/datetime/time-zone-overrides` so recent rule changes apply on every engine.")
+}
diff --git a/biome.json b/biome.json
index 64f4a003c..c516c2fe3 100644
--- a/biome.json
+++ b/biome.json
@@ -3,7 +3,8 @@
"root": true,
"plugins": [
"./biome-plugins/use-icon-button-label.grit",
- "./biome-plugins/no-raw-datetime-formatting.grit"
+ "./biome-plugins/no-raw-datetime-formatting.grit",
+ "./biome-plugins/no-unresolved-dayjs-tz.grit"
],
"assist": {
"actions": {
diff --git a/packages/database/prisma/migrations/20260930120000_shift_manitoba_winter_times/migration.sql b/packages/database/prisma/migrations/20260930120000_shift_manitoba_winter_times/migration.sql
new file mode 100644
index 000000000..f67e9b87e
--- /dev/null
+++ b/packages/database/prisma/migrations/20260930120000_shift_manitoba_winter_times/migration.sql
@@ -0,0 +1,48 @@
+-- Manitoba stops falling back on 2026-11-01 and stays on UTC-5. No tz data
+-- had the change when the app started resolving it, so every timed value in
+-- a Manitoba zone that falls in a winter the old rules put on UTC-6 was
+-- stored an hour late: 10:00 entered for Nov 5 became 16:00Z instead of
+-- 15:00Z. Everyone saw 10:00 because every engine made the same mistake, so
+-- shifting back an hour keeps what people see and makes the instant true.
+--
+-- Runs once, in the same release as the resolver, so every row it touches
+-- was saved under the old rules. The old rules' winters run from the first
+-- Sunday of November at 02:00 CDT (07:00 UTC) to the second Sunday of March
+-- at 02:00 CST (08:00 UTC). They are built from that calendar rule rather
+-- than with AT TIME ZONE, which would read Postgres's own, possibly stale,
+-- tz data.
+--
+-- A timed event's end is its start plus its duration, so both move together.
+
+CREATE TEMPORARY TABLE "old_manitoba_winters" AS
+SELECT
+ ("fall" + (7 - extract(dow FROM "fall")::int) % 7) + time '07:00' AS "start",
+ ("spring" + (7 - extract(dow FROM "spring")::int) % 7 + 7) + time '08:00' AS "end"
+FROM (
+ SELECT make_date("year", 11, 1) AS "fall", make_date("year" + 1, 3, 1) AS "spring"
+ FROM generate_series(2026, 2099) AS "year"
+) AS "years";
+
+UPDATE "options" SET "start_time" = "start_time" - interval '1 hour'
+WHERE "duration_minutes" > 0
+ AND "poll_id" IN (
+ SELECT "id" FROM "polls"
+ WHERE "time_zone" IN ('America/Winnipeg', 'Canada/Central')
+ )
+ AND EXISTS (
+ SELECT 1 FROM "old_manitoba_winters" AS "winter"
+ WHERE "options"."start_time" >= "winter"."start"
+ AND "options"."start_time" < "winter"."end"
+ );
+
+UPDATE "scheduled_events"
+SET "start" = "start" - interval '1 hour', "end" = "end" - interval '1 hour'
+WHERE NOT "all_day"
+ AND "time_zone" IN ('America/Winnipeg', 'Canada/Central')
+ AND EXISTS (
+ SELECT 1 FROM "old_manitoba_winters" AS "winter"
+ WHERE "scheduled_events"."start" >= "winter"."start"
+ AND "scheduled_events"."start" < "winter"."end"
+ );
+
+DROP TABLE "old_manitoba_winters";