Skip to content

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

🐛 Offer and draw available times in the poll's time zone (#3618)

Luke Vella2df0cd128ec9
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 7ad84fde5..f092e7187 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -1205,7 +1205,8 @@
"webhookTestEventRespondedWith": "Endpoint responded {status}",
"webhookTestEventSending": "Sending test event",
"webhookUrl": "URL",
- "weekCalendarSkippedTime": "That time is skipped when the clocks change in {timeZone}",
+ "weekCalendarClocksGoForward": "Clocks go forward",
+ "weekCalendarClocksGoForwardHelp": "Clocks in {timeZone} skip this time when they go forward",
"weekView": "Week view",
"whiteLabelAddon": "White Label Add-on",
"whiteLabelAddonDescription": "This add-on allows you to brand Rallly with your own logo and colors.",
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/month-calendar.tsx b/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/month-calendar.tsx
index c2bf474a1..7553cfd0b 100644
--- a/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/month-calendar.tsx
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/month-calendar.tsx
@@ -33,19 +33,27 @@ import { Trans, useTranslation } from "@/i18n/client";
import { useDateTimeConfig } from "@/lib/datetime/client";
import { Duration } from "@/lib/datetime/duration";
import { formatDateParts } from "@/lib/datetime/format";
+import {
+ addMinutesToWallTime,
+ wallTimeDiffInMinutes,
+} from "@/lib/datetime/wall-time";
import { dayjs } from "@/lib/dayjs";
import {
expectTimeOption,
getBrowserTimeZone,
} from "@/lib/utils/date-time-utils";
import type { DateTimeOption, DateTimePickerProps } from "../types";
-import {
- formatDateWithoutTime,
- formatDateWithoutTz,
- removeAllOptionsForDay,
-} from "../utils";
+import { formatDateWithoutTime, removeAllOptionsForDay } from "../utils";
import TimePicker from "./time-picker";
+// Options are floating wall-clock strings, so times are computed on the
+// strings themselves and never pass through the browser's zone.
+const middayOf = (date: string) => `${date}T12:00:00`;
+
+/** Local noon of the option's calendar date, for navigating the date picker. */
+const navigationDateOf = (wallTime: string) =>
+ new Date(middayOf(wallTime.slice(0, 10)));
+
const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
options,
onNavigate,
@@ -53,6 +61,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
onChange,
duration,
onChangeDuration,
+ timeZone,
}) => {
const { t } = useTranslation();
const { locale } = useDateTimeConfig();
@@ -72,7 +81,7 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
// single value the radio group selects it; differing values show as "Mixed".
const optionDurations = options.flatMap((option) =>
option.type === "timeSlot"
- ? [dayjs(option.end).diff(option.start, "minute")]
+ ? [wallTimeDiffInMinutes(option.start, option.end)]
: [],
);
const uniformDuration =
@@ -126,16 +135,12 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
// existing start time (defaulting all-day options to midday).
onChange(
options.map<DateTimeOption>((option) => {
- const startDate =
- option.type === "timeSlot"
- ? new Date(option.start)
- : new Date(`${option.date}T12:00:00`);
+ const start =
+ option.type === "timeSlot" ? option.start : middayOf(option.date);
return {
type: "timeSlot",
- start: formatDateWithoutTz(startDate),
- end: formatDateWithoutTz(
- dayjs(startDate).add(minutes, "minutes").toDate(),
- ),
+ start,
+ end: addMinutesToWallTime(start, minutes),
};
}),
);
@@ -267,18 +272,15 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
const selectedDate = dayjs(day.date)
.set("hour", 12)
.toDate();
+ const date = formatDateWithoutTime(selectedDate);
const newOption: DateTimeOption = !isTimedEvent
- ? {
- type: "date",
- date: formatDateWithoutTime(selectedDate),
- }
+ ? { type: "date", date }
: {
type: "timeSlot",
- start: formatDateWithoutTz(selectedDate),
- end: formatDateWithoutTz(
- dayjs(selectedDate)
- .add(slotDuration, "minutes")
- .toDate(),
+ start: middayOf(date),
+ end: addMinutesToWallTime(
+ middayOf(date),
+ slotDuration,
),
};
@@ -377,53 +379,51 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
if (option.type === "date") {
throw new Error("Expected timeSlot but got date");
}
- const startDate = new Date(option.start);
return (
<div
key={index}
className="flex items-center space-x-3"
>
<TimePicker
- value={startDate}
+ value={option.start}
+ timeZone={timeZone}
onChange={(newStart) => {
- const newEnd = dayjs(newStart).add(
- slotDuration,
- "minutes",
- );
-
// replace enter with updated start time
onChange([
...options.slice(0, index),
{
...option,
- start: formatDateWithoutTz(newStart),
- end: formatDateWithoutTz(
- newEnd.toDate(),
+ start: newStart,
+ end: addMinutesToWallTime(
+ newStart,
+ slotDuration,
),
},
...options.slice(index + 1),
]);
- onNavigate(newStart);
- onChangeDuration(
- newEnd.diff(newStart, "minutes"),
- );
+ onNavigate(navigationDateOf(newStart));
+ onChangeDuration(slotDuration);
}}
/>
<TimePicker
- value={new Date(option.end)}
- after={startDate}
+ value={option.end}
+ after={option.start}
+ timeZone={timeZone}
onChange={(newEnd) => {
onChange([
...options.slice(0, index),
{
...option,
- end: formatDateWithoutTz(newEnd),
+ end: newEnd,
},
...options.slice(index + 1),
]);
- onNavigate(newEnd);
+ onNavigate(navigationDateOf(newEnd));
onChangeDuration(
- dayjs(newEnd).diff(startDate, "minutes"),
+ wallTimeDiffInMinutes(
+ option.start,
+ newEnd,
+ ),
);
}}
/>
@@ -453,24 +453,22 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
.option,
);
- const startTime = dayjs(lastOption.end).isSame(
- lastOption.start,
- "day",
- )
- ? // if the end time of the previous option is on the same day as the start time, use the end time
- lastOption.end
- : // otherwise use the start time
- lastOption.start;
+ const startTime =
+ lastOption.end.slice(0, 10) ===
+ lastOption.start.slice(0, 10)
+ ? // if the end time of the previous option is on the same day as the start time, use the end time
+ lastOption.end
+ : // otherwise use the start time
+ lastOption.start;
onChange([
...options,
{
type: "timeSlot",
start: startTime,
- end: formatDateWithoutTz(
- dayjs(new Date(startTime))
- .add(slotDuration, "minutes")
- .toDate(),
+ end: addMinutesToWallTime(
+ startTime,
+ slotDuration,
),
},
]);
@@ -525,9 +523,10 @@ const MonthCalendar: React.FunctionComponent<DateTimePickerProps> = ({
newOptions.push({
type: "timeSlot",
start: start,
- end: dayjs(start)
- .add(slotDuration, "minutes")
- .format("YYYY-MM-DDTHH:mm"),
+ end: addMinutesToWallTime(
+ start,
+ slotDuration,
+ ),
});
});
},
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/time-picker.tsx b/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/time-picker.tsx
index eaef46bb7..813ffd926 100644
--- a/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/time-picker.tsx
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/month-calendar/time-picker.tsx
@@ -11,13 +11,19 @@ import { useTranslation } from "@/i18n/client";
import { useDateTimeConfig } from "@/lib/datetime/client";
import { Duration } from "@/lib/datetime/duration";
import { formatDateTime } from "@/lib/datetime/format";
-import { dayjs } from "@/lib/dayjs";
+import { wallTimeDiffInMinutes } from "@/lib/datetime/wall-time";
+import { getTimeOptions } from "../utils";
+import { FLOATING_TIME_ZONE, floatingToDate } from "../week-calendar-utils";
export interface TimePickerProps {
- value?: Date;
- after?: Date;
+ /** Floating wall-clock time, YYYY-MM-DDTHH:mm:ss. */
+ value?: string;
+ /** When set, offers the 24 hours after this time instead of `value`'s day. */
+ after?: string;
+ /** The poll's zone; times its clocks skip aren't offered. */
+ timeZone?: string;
className?: string;
- onChange?: (value: Date) => void;
+ onChange?: (value: string) => void;
}
const TimePicker: React.FunctionComponent<TimePickerProps> = ({
@@ -25,47 +31,48 @@ const TimePicker: React.FunctionComponent<TimePickerProps> = ({
onChange,
className,
after,
+ timeZone,
}) => {
const { locale, timeFormat } = useDateTimeConfig();
const { t } = useTranslation();
const [open, setOpen] = React.useState(false);
- // The form works in naive local times, so options format in the system zone.
- const formatTime = (time: string | Date) =>
- formatDateTime(new Date(time), { preset: "time", locale, timeFormat });
+ const formatTime = (time: string) =>
+ formatDateTime(floatingToDate(time), {
+ preset: "time",
+ locale,
+ timeFormat,
+ timeZone: FLOATING_TIME_ZONE,
+ });
- const getOptions = React.useCallback(() => {
- if (!open) {
- return [dayjs(value).toISOString()];
- }
- let cursor = after
- ? dayjs(after).add(15, "minutes")
- : dayjs(value).startOf("day");
-
- const res: string[] = [];
+ const options = React.useMemo(
+ () =>
+ value
+ ? open
+ ? getTimeOptions({ value, after, timeZone })
+ : [value]
+ : [],
+ [after, open, timeZone, value],
+ );
- if (after) {
- let cursor = dayjs(after).add(15, "minutes");
- while (cursor.diff(after, "hours") < 24) {
- res.push(cursor.toISOString());
- cursor = cursor.add(15, "minutes");
- }
- } else {
- cursor = dayjs(value).startOf("day");
- while (cursor.isSame(value, "day")) {
- res.push(cursor.toISOString());
- cursor = cursor.add(15, "minutes");
- }
- }
- return res;
- }, [after, open, value]);
+ const renderOption = (option: string) => (
+ <div className="flex items-center gap-2">
+ <span>{formatTime(option)}</span>
+ {after ? (
+ <Duration
+ className="text-muted-foreground text-sm"
+ minutes={wallTimeDiffInMinutes(after, option)}
+ />
+ ) : null}
+ </div>
+ );
return (
<Select
- value={value?.toISOString()}
+ value={value}
onValueChange={(newValue) => {
if (newValue) {
- onChange?.(new Date(newValue));
+ onChange?.(newValue);
}
}}
open={open}
@@ -78,52 +85,18 @@ const TimePicker: React.FunctionComponent<TimePickerProps> = ({
})}
>
{(selected: string | null | undefined) =>
- selected ? (
- <div className="flex items-center gap-2">
- <span>{formatTime(selected)}</span>
- {after ? (
- <Duration
- className="text-muted-foreground text-sm"
- minutes={dayjs(selected).diff(after, "minute")}
- />
- ) : null}
- </div>
- ) : (
- t("timePickerSelectTime", { defaultValue: "Select time" })
- )
+ selected
+ ? renderOption(selected)
+ : t("timePickerSelectTime", { defaultValue: "Select time" })
}
</SelectValue>
</SelectTrigger>
<SelectContent>
- {open ? (
- getOptions().map((option) => {
- return (
- <SelectItem key={option} value={dayjs(option).toISOString()}>
- <div className="flex items-center gap-2">
- <span>{formatTime(option)}</span>
- {after ? (
- <Duration
- className="text-muted-foreground text-sm"
- minutes={dayjs(option).diff(after, "minute")}
- />
- ) : null}
- </div>
- </SelectItem>
- );
- })
- ) : (
- <SelectItem value={dayjs(value).toISOString()}>
- <div className="flex items-center gap-2">
- <span>{formatTime(dayjs(value).toDate())}</span>
- {after ? (
- <Duration
- className="text-muted-foreground text-sm"
- minutes={dayjs(value).diff(after, "minute")}
- />
- ) : null}
- </div>
+ {options.map((option) => (
+ <SelectItem key={option} value={option}>
+ {renderOption(option)}
</SelectItem>
- )}
+ ))}
</SelectContent>
</Select>
);
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/utils.test.ts b/apps/web/src/features/poll/components/forms/poll-options-form/utils.test.ts
new file mode 100644
index 000000000..c99e583da
--- /dev/null
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/utils.test.ts
@@ -0,0 +1,77 @@
+import { afterEach, describe, expect, it } from "vitest";
+import { getTimeOptions } from "./utils";
+
+const hoursOf = (options: string[]) =>
+ [...new Set(options.map((option) => option.slice(11, 13)))].join(",");
+
+describe("getTimeOptions", () => {
+ const originalTimeZone = process.env.TZ;
+ afterEach(() => {
+ process.env.TZ = originalTimeZone;
+ });
+
+ it.each([
+ "America/Chicago",
+ "Asia/Kathmandu",
+ ])("offers the poll zone's times whatever the browser's zone (%s)", (browserTimeZone) => {
+ process.env.TZ = browserTimeZone;
+ const chicago = getTimeOptions({
+ value: "2027-03-14T12:00:00",
+ timeZone: "America/Chicago",
+ });
+ expect(chicago).toHaveLength(92);
+ expect(hoursOf(chicago)).not.toContain("02");
+ expect(chicago).toContain("2027-03-14T01:45:00");
+ expect(chicago).toContain("2027-03-14T03:00:00");
+
+ const kathmandu = getTimeOptions({
+ value: "2027-03-14T12:00:00",
+ timeZone: "Asia/Kathmandu",
+ });
+ expect(kathmandu).toHaveLength(96);
+ expect(kathmandu).toContain("2027-03-14T02:30:00");
+ });
+
+ it("keeps the repeated fall back hour once", () => {
+ const options = getTimeOptions({
+ value: "2026-11-01T12:00:00",
+ timeZone: "America/Chicago",
+ });
+ expect(options).toHaveLength(96);
+ expect(new Set(options).size).toBe(96);
+ });
+
+ it("offers every time for a poll without a zone", () => {
+ expect(getTimeOptions({ value: "2027-03-14T12:00:00" })).toHaveLength(96);
+ });
+
+ it("keeps the current value even when the zone skips it", () => {
+ expect(
+ getTimeOptions({
+ value: "2027-03-14T02:30:00",
+ timeZone: "America/Chicago",
+ }),
+ ).toContain("2027-03-14T02:30:00");
+ });
+
+ it("offers end times inside the skipped hour", () => {
+ expect(
+ getTimeOptions({
+ value: "2027-03-14T02:30:00",
+ after: "2027-03-14T01:30:00",
+ timeZone: "America/Chicago",
+ }),
+ ).toContain("2027-03-14T02:30:00");
+ });
+
+ it("offers the 24 hours after a start, past midnight", () => {
+ const options = getTimeOptions({
+ value: "2026-11-03T23:30:00",
+ after: "2026-11-03T23:00:00",
+ timeZone: "America/Chicago",
+ });
+ expect(options[0]).toBe("2026-11-03T23:15:00");
+ expect(options.at(-1)).toBe("2026-11-04T23:00:00");
+ expect(options).toHaveLength(96);
+ });
+});
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/utils.ts b/apps/web/src/features/poll/components/forms/poll-options-form/utils.ts
index 42540dce5..0126ccd7c 100644
--- a/apps/web/src/features/poll/components/forms/poll-options-form/utils.ts
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/utils.ts
@@ -1,3 +1,4 @@
+import { addMinutesToWallTime, wallTimeExists } from "@/lib/datetime/wall-time";
import { dayjs } from "@/lib/dayjs";
import type { DateTimeOption } from "./types";
@@ -9,10 +10,6 @@ export const isAllDay = (options: DateTimeOption[]) =>
export const hasMixedOptionTypes = (options: DateTimeOption[]) =>
options.some((option) => option.type !== options[0]?.type);
-export const formatDateWithoutTz = (date: Date): string => {
- return dayjs(date).format("YYYY-MM-DDTHH:mm:ss");
-};
-
export const formatDateWithoutTime = (date: Date): string => {
return dayjs(date).format("YYYY-MM-DD");
};
@@ -28,3 +25,40 @@ export const removeAllOptionsForDay = (
);
});
};
+
+const TIME_STEP_MINUTES = 15;
+const DAY_MINUTES = 24 * 60;
+
+/**
+ * Wall-clock times a time picker offers, in 15 minute steps: the day of
+ * `value`, or the 24 hours after `after`. Start times the poll's zone skips
+ * when its clocks spring forward are left out; end times may fall in that
+ * hour, and `value` itself always stays.
+ */
+export function getTimeOptions({
+ value,
+ after,
+ timeZone,
+}: {
+ value: string;
+ after?: string;
+ timeZone?: string;
+}) {
+ const options: string[] = [];
+ if (after) {
+ for (let m = TIME_STEP_MINUTES; m <= DAY_MINUTES; m += TIME_STEP_MINUTES) {
+ options.push(addMinutesToWallTime(after, m));
+ }
+ } else {
+ const midnight = `${value.slice(0, 10)}T00:00:00`;
+ for (let m = 0; m < DAY_MINUTES; m += TIME_STEP_MINUTES) {
+ options.push(addMinutesToWallTime(midnight, m));
+ }
+ }
+ if (after || !timeZone) {
+ return options;
+ }
+ return options.filter(
+ (option) => option === value || wallTimeExists(option, timeZone),
+ );
+}
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar-utils.test.ts b/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar-utils.test.ts
index a50fcf629..246828068 100644
--- a/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar-utils.test.ts
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar-utils.test.ts
@@ -9,8 +9,9 @@ import {
instantToFloating,
isDuplicate,
optionsToEvents,
- slotExistsIn,
+ skippedMinuteRanges,
slotToTimeOption,
+ startExistsIn,
} from "./week-calendar-utils";
const d = floatingToDate;
@@ -80,29 +81,41 @@ describe("instantToFloating / floatingToInstant", () => {
});
});
-describe("slotExistsIn", () => {
- const springForward = {
- type: "timeSlot",
- start: "2027-03-14T02:00:00",
- end: "2027-03-14T03:00:00",
- } as const;
+describe("startExistsIn", () => {
+ const slot = (start: string, end: string) =>
+ ({ type: "timeSlot", start, end }) as const;
it("rejects a slot that starts in a skipped hour of the poll's zone", () => {
- expect(slotExistsIn(springForward, "America/Chicago")).toBe(false);
+ expect(
+ startExistsIn(
+ slot("2027-03-14T02:00:00", "2027-03-14T03:00:00"),
+ "America/Chicago",
+ ),
+ ).toBe(false);
+ });
+
+ it("accepts a slot that runs into the skipped hour", () => {
+ expect(
+ startExistsIn(
+ slot("2027-03-14T01:30:00", "2027-03-14T02:30:00"),
+ "America/Chicago",
+ ),
+ ).toBe(true);
});
- it("accepts the same slot in a poll zone without that change", () => {
- expect(slotExistsIn(springForward, "Asia/Kathmandu")).toBe(true);
+ it("accepts the same start in a poll zone without that change", () => {
+ expect(
+ startExistsIn(
+ slot("2027-03-14T02:00:00", "2027-03-14T03:00:00"),
+ "Asia/Kathmandu",
+ ),
+ ).toBe(true);
});
it("accepts a slot in the repeated fall back hour", () => {
expect(
- slotExistsIn(
- {
- type: "timeSlot",
- start: "2026-11-01T01:00:00",
- end: "2026-11-01T02:00:00",
- },
+ startExistsIn(
+ slot("2026-11-01T01:00:00", "2026-11-01T02:00:00"),
"America/Chicago",
),
).toBe(true);
@@ -147,3 +160,23 @@ describe("durationMinutes / cap", () => {
expect(DURATION_CAP_MINUTES).toBe(1440);
});
});
+
+describe("skippedMinuteRanges", () => {
+ it("finds the hour Chicago skips when it springs forward", () => {
+ expect(skippedMinuteRanges("2027-03-14", "America/Chicago")).toEqual([
+ [120, 180],
+ ]);
+ });
+
+ it("finds a half hour change", () => {
+ expect(skippedMinuteRanges("2026-10-04", "Australia/Lord_Howe")).toEqual([
+ [120, 150],
+ ]);
+ });
+
+ it("is empty when clocks fall back or don't change", () => {
+ expect(skippedMinuteRanges("2026-11-01", "America/Chicago")).toEqual([]);
+ expect(skippedMinuteRanges("2027-03-15", "America/Chicago")).toEqual([]);
+ expect(skippedMinuteRanges("2027-03-14", "Asia/Kathmandu")).toEqual([]);
+ });
+});
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar-utils.ts b/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar-utils.ts
index 2f4a36302..2f1a5ae8d 100644
--- a/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar-utils.ts
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar-utils.ts
@@ -1,5 +1,6 @@
import type { CalendarEvent } from "@rallly/ui/event-calendar";
import {
+ addMinutesToWallTime,
instantToWallTime,
wallTimeExists,
wallTimeToInstant,
@@ -28,10 +29,12 @@ export const instantToFloating = (date: Date, timeZone: string) =>
export const floatingToInstant = (date: Date, timeZone: string) =>
wallTimeToInstant(dateToFloating(date), timeZone);
-/** Whether both ends of the slot are times clocks in `timeZone` actually read. */
-export const slotExistsIn = (option: TimeOption, timeZone: string) =>
- wallTimeExists(option.start, timeZone) &&
- wallTimeExists(option.end, timeZone);
+/**
+ * Whether the slot starts at a time clocks in `timeZone` actually read. Only
+ * the start matters: a slot may run across the hour the clocks skip.
+ */
+export const startExistsIn = (option: TimeOption, timeZone: string) =>
+ wallTimeExists(option.start, timeZone);
export function eventId(option: DateTimeOption): string {
return option.type === "date"
@@ -84,3 +87,33 @@ export function isDuplicate(
export function durationMinutes(start: Date, end: Date): number {
return Math.round((end.getTime() - start.getTime()) / 60_000);
}
+
+const SKIP_STEP_MINUTES = 15;
+
+/**
+ * Minute ranges [start, end) of `date` (YYYY-MM-DD) that clocks in `timeZone`
+ * skip when they spring forward. Empty on every other day.
+ */
+export function skippedMinuteRanges(date: string, timeZone: string) {
+ const midnight = `${date}T00:00:00`;
+ const nextMidnight = addMinutesToWallTime(midnight, DURATION_CAP_MINUTES);
+ const dayLength =
+ wallTimeToInstant(nextMidnight, timeZone).getTime() -
+ wallTimeToInstant(midnight, timeZone).getTime();
+ if (dayLength >= DURATION_CAP_MINUTES * 60_000) {
+ return [];
+ }
+ const ranges: Array<[number, number]> = [];
+ for (let m = 0; m < DURATION_CAP_MINUTES; m += SKIP_STEP_MINUTES) {
+ if (wallTimeExists(addMinutesToWallTime(midnight, m), timeZone)) {
+ continue;
+ }
+ const last = ranges.at(-1);
+ if (last && last[1] === m) {
+ last[1] = m + SKIP_STEP_MINUTES;
+ } else {
+ ranges.push([m, m + SKIP_STEP_MINUTES]);
+ }
+ }
+ return ranges;
+}
diff --git a/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar.tsx b/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar.tsx
index 98bb43e2d..82bf86c95 100644
--- a/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar.tsx
+++ b/apps/web/src/features/poll/components/forms/poll-options-form/week-calendar.tsx
@@ -16,10 +16,9 @@ import {
EventCalendarWeekView,
useEventCalendarNavigation,
} from "@rallly/ui/event-calendar";
-import { toast } from "@rallly/ui/sonner";
import React from "react";
import { createBreakpoint } from "react-use";
-import { useTranslation } from "@/i18n/client";
+import { Trans, useTranslation } from "@/i18n/client";
import { useDateTime, useDateTimeConfig } from "@/lib/datetime/client";
import { getBrowserTimeZone } from "@/lib/utils/date-time-utils";
@@ -27,6 +26,7 @@ import DateNavigationToolbar from "./date-navigation-toolbar";
import type { DateTimePickerProps, TimeOption } from "./types";
import {
DURATION_CAP_MINUTES,
+ dateToFloating,
durationMinutes,
FLOATING_TIME_ZONE,
floatingToDate,
@@ -34,8 +34,9 @@ import {
instantToFloating,
isDuplicate,
optionsToEvents,
- slotExistsIn,
+ skippedMinuteRanges,
slotToTimeOption,
+ startExistsIn,
} from "./week-calendar-utils";
const useDevice = createBreakpoint({ desktop: 720, mobile: 360 });
@@ -86,21 +87,13 @@ const WeekCalendar: React.FunctionComponent<DateTimePickerProps> = ({
const handleNavigate = (next: Date) =>
onNavigate(floatingToInstant(next, viewerTimeZone));
- // A slot whose start or end is skipped when the poll's clocks spring
- // forward would silently shift on save, so it can't be picked at all.
+ // A slot starting in the hour the poll's clocks skip when they spring
+ // forward would silently shift on save, so it can't be picked. The skipped
+ // hour is drawn as a disabled band that takes the pointer itself.
const isAvailable = (option: TimeOption) =>
- !pollTimeZone || slotExistsIn(option, pollTimeZone);
+ !pollTimeZone || startExistsIn(option, pollTimeZone);
const isAvailableSlot = (start: Date, end: Date) =>
isAvailable(slotToTimeOption(start, end));
- const rejectSkippedTime = () => {
- toast.error(
- t("weekCalendarSkippedTime", {
- defaultValue:
- "That time is skipped when the clocks change in {timeZone}",
- timeZone: pollTimeZone,
- }),
- );
- };
const apiRef = React.useRef<EventCalendarApi | null>(null);
const hasScrolledRef = React.useRef(false);
@@ -173,7 +166,6 @@ const WeekCalendar: React.FunctionComponent<DateTimePickerProps> = ({
}
const candidate = slotToTimeOption(slot.start, slot.end);
if (!isAvailable(candidate)) {
- rejectSkippedTime();
return;
}
const diff = durationMinutes(slot.start, slot.end);
@@ -193,7 +185,6 @@ const WeekCalendar: React.FunctionComponent<DateTimePickerProps> = ({
const end = new Date(start.getTime() + (duration || 60) * 60 * 1000);
const candidate = slotToTimeOption(start, end);
if (!isAvailable(candidate)) {
- rejectSkippedTime();
return;
}
if (!isDuplicate(options, candidate)) {
@@ -288,6 +279,33 @@ const WeekCalendar: React.FunctionComponent<DateTimePickerProps> = ({
// matching the default's top-edge suppression.
hour === 0 && minute === 0 ? null : formatTime(time)
}
+ renderDayColumnBackground={({ day, boundsStartMin }) =>
+ pollTimeZone
+ ? skippedMinuteRanges(
+ dateToFloating(day).slice(0, 10),
+ pollTimeZone,
+ ).map(([start, end]) => (
+ <div
+ key={start}
+ className="pointer-events-auto absolute inset-x-0 cursor-not-allowed overflow-hidden border-y border-dashed bg-[repeating-linear-gradient(135deg,transparent_0_6px,var(--color-border)_6px_7px)] bg-muted px-1.5 py-0.5 text-muted-foreground text-xs"
+ style={{
+ top: `calc(var(--ec-hour-height) * ${(start - boundsStartMin) / 60})`,
+ height: `calc(var(--ec-hour-height) * ${(end - start) / 60})`,
+ }}
+ title={t("weekCalendarClocksGoForwardHelp", {
+ defaultValue:
+ "Clocks in {timeZone} skip this time when they go forward",
+ timeZone: pollTimeZone,
+ })}
+ >
+ <Trans
+ i18nKey="weekCalendarClocksGoForward"
+ defaults="Clocks go forward"
+ />
+ </div>
+ ))
+ : null
+ }
onSelectSlot={handleSelectSlot}
onSlotClick={handleSlotClick}
onEventClick={handleEventClick}