Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calendar): show a weekly rule without weekdays on the start's weekday (#8663)

gbirman54606fd2dffd
diff --git a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
index 0cba6e64c6..1d01f4e7a7 100644
--- a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
+++ b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
@@ -173,6 +173,44 @@ describe('recurrence submission', () => {
]);
});
+ // October 1, 2026 is a Thursday.
+ it('reads a weekly rule without weekdays as the weekly preset and keeps its text', () => {
+ const controller = controllerFor(
+ { ...recurringValue, recurrenceLines: ['RRULE:FREQ=WEEKLY'] },
+ { isEdit: true }
+ );
+ expect(controller.recurrenceChoice()).toBe('weekly');
+ expect(controller.submitValues()?.recurrenceLines).toEqual([
+ 'RRULE:FREQ=WEEKLY',
+ ]);
+
+ // The rule follows the start, as the preset does.
+ controller.setStart('2026-10-02T18:00');
+ controller.setField('end', '2026-10-02T18:30');
+ expect(controller.submitValues()?.recurrenceLines).toEqual([
+ 'RRULE:FREQ=WEEKLY',
+ ]);
+ });
+
+ it('opens a weekly rule with an end but no weekdays on the start’s weekday', () => {
+ const controller = controllerFor(
+ { ...recurringValue, recurrenceLines: ['RRULE:FREQ=WEEKLY;COUNT=3'] },
+ { isEdit: true }
+ );
+ expect(controller.recurrenceChoice()).toBe('custom');
+ expect(controller.customConfig().byDay).toEqual(['TH']);
+ expect(controller.submitValues()?.recurrenceLines).toEqual([
+ 'RRULE:FREQ=WEEKLY;COUNT=3',
+ ]);
+
+ // Moved to Friday, the series keeps the Thursday the editor shows.
+ controller.setStart('2026-10-02T18:00');
+ controller.setField('end', '2026-10-02T18:30');
+ expect(controller.submitValues()?.recurrenceLines).toEqual([
+ 'RRULE:FREQ=WEEKLY;BYDAY=TH;COUNT=3',
+ ]);
+ });
+
it('converts UNTIL when changing a timed event to all-day', () => {
const controller = controllerFor(
{
diff --git a/apps/web/src/features/calendar/components/composer/event-form-model.ts b/apps/web/src/features/calendar/components/composer/event-form-model.ts
index 4b6b1a7423..da930439c8 100644
--- a/apps/web/src/features/calendar/components/composer/event-form-model.ts
+++ b/apps/web/src/features/calendar/components/composer/event-form-model.ts
@@ -40,6 +40,8 @@ import {
type RecurrenceConfig,
recurrenceConfigsEqual,
recurrencePresetsFor,
+ WEEKDAY_CODES,
+ type WeekdayCode,
} from '../../utils/recurrence';
import type { EventEditorOutOfOffice } from './out-of-office';
@@ -473,13 +475,38 @@ export interface CreateEventEditorStateOptions {
isEdit?: boolean;
}
+/** When the event starts, in the zone its recurrence is expressed in. */
+function recurrenceStartOf(
+ values: Pick<EventEditorInitialValues, 'allDay' | 'start'>,
+ timeZone?: string
+) {
+ const parsed = values.allDay
+ ? parseISO(values.start)
+ : new Date(values.start);
+ if (Number.isNaN(parsed.getTime())) return undefined;
+ return !values.allDay && timeZone ? TZDateMini.tz(timeZone, parsed) : parsed;
+}
+
+/**
+ * The editable form of the event's rule, read at `start`. A weekly rule
+ * without BYDAY repeats on the start's weekday (RFC 5545), so that weekday
+ * is spelled out, as the weekly preset and the custom editor's day chips
+ * show it.
+ */
function recurrenceConfigFor(
values: EventEditorInitialValues,
- timeZone?: string
+ timeZone?: string,
+ start: Pick<EventEditorInitialValues, 'allDay' | 'start'> = values
) {
- return values.recurrenceLines.length > 0
- ? parseRecurrenceConfig(values.recurrenceLines, timeZone)
- : undefined;
+ if (values.recurrenceLines.length === 0) return undefined;
+ const config = parseRecurrenceConfig(values.recurrenceLines, timeZone);
+ if (config?.frequency !== 'WEEKLY' || config.byDay.length > 0) return config;
+ const startsAt = recurrenceStartOf(start, timeZone);
+ if (!startsAt) return config;
+ return {
+ ...config,
+ byDay: [WEEKDAY_CODES[startsAt.getDay()] as WeekdayCode],
+ };
}
function recurrenceChoiceFor(
@@ -489,7 +516,7 @@ function recurrenceChoiceFor(
if (values.recurrenceLines.length === 0) return 'none';
const config = recurrenceConfigFor(values, timeZone);
if (!config) return 'existing';
- const start = values.allDay ? parseISO(values.start) : new Date(values.start);
+ const start = recurrenceStartOf(values, timeZone) ?? new Date();
const preset = recurrencePresetsFor(start).find((candidate) =>
recurrenceConfigsEqual(candidate.config, config)
);
@@ -575,7 +602,13 @@ export function createEventEditorState(options: CreateEventEditorStateOptions) {
? customConfig()
: presets().find((candidate) => candidate.id === choice)?.config;
if (!config) return undefined;
- const originalConfig = initialConfig();
+ // What the stored rule means at the current start: a weekly rule without
+ // BYDAY follows the start to another weekday.
+ const originalConfig = recurrenceConfigFor(
+ initialValues(),
+ options.recurrenceTimeZone,
+ options.state()
+ );
if (
originalConfig &&
options.state().allDay === initialValues().allDay &&
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index faf0aa2b82..bc0281d71b 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -448,6 +448,10 @@ by the organizer or a guest the organizer lets modify the event.
Test reminder removal as well as changing its time, including a series whose stored
rule contains `INTERVAL=1`, `WKST`, differently ordered weekdays, or a precise `UNTIL`:
an untouched rule must not be reformatted and included in a reminder-only PATCH.
+A weekly rule without `BYDAY` repeats on the start's weekday: plain `FREQ=WEEKLY` opens on the
+`Weekly on <day>` preset, and one with an end (such as `COUNT=3`) opens `Custom` with that day
+selected, since the presets never end. Either is saved as written while untouched; moving the
+start to another weekday keeps a custom rule on the day the editor shows.
As in Google Calendar, the guests row of the details popover (a bottom sheet on phones)
carries `Copy guest emails` and `Email guests` icon buttons, both hidden when you are the
only guest (always so on a snapshot). Copying puts every guest's address on the clipboard,