fix(web,mobile): snooze menu no longer offers the same wake time twice (#8741)
This commit is contained in:
1 parent
ac4aae101d
commit
7980dfddb1
2 files changed
+24
-7
No files matched your search
@@ -394,7 +394,9 @@ function addSnoozeDays(base: Date, days: number): Date {
|
||||
/**
|
||||
* Shared "snooze until" choices for every client. "This evening" only
|
||||
* appears while it is meaningfully before evening; after that the calendar
|
||||
* choices start at "Tomorrow".
|
||||
* choices start at "Tomorrow". Calendar presets that land on the same
|
||||
* instant collapse: on Sundays "Tomorrow" and "Next week" are both Monday
|
||||
* morning, so only "Tomorrow" is offered.
|
||||
*/
|
||||
export function resolveSnoozePresets(now: Date): ReadonlyArray<SnoozePreset> {
|
||||
const inAnHour = new Date(now.getTime() + HOUR_MS);
|
||||
@@ -434,12 +436,14 @@ export function resolveSnoozePresets(now: Date): ReadonlyArray<SnoozePreset> {
|
||||
|
||||
const daysUntilMonday = (1 - now.getDay() + 7) % 7 || 7;
|
||||
const nextWeek = snoozeAtHour(addSnoozeDays(now, daysUntilMonday), MORNING_HOUR);
|
||||
presets.push({
|
||||
id: "next-week",
|
||||
label: "Next week",
|
||||
whenLabel: `${nextWeek.toLocaleDateString(undefined, { weekday: "short" })} ${snoozeTimeOfDayLabel(nextWeek)}`,
|
||||
snoozedUntil: nextWeek.toISOString(),
|
||||
});
|
||||
if (nextWeek.getTime() !== tomorrow.getTime()) {
|
||||
presets.push({
|
||||
id: "next-week",
|
||||
label: "Next week",
|
||||
whenLabel: `${nextWeek.toLocaleDateString(undefined, { weekday: "short" })} ${snoozeTimeOfDayLabel(nextWeek)}`,
|
||||
snoozedUntil: nextWeek.toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
return presets;
|
||||
}
|
||||
|
||||
@@ -297,4 +297,17 @@ describe("resolveSnoozePresets", () => {
|
||||
expect(nextWeek.getDay()).toBe(1);
|
||||
expect(nextWeek.getDate()).toBe(13);
|
||||
});
|
||||
|
||||
it("drops next week on Sundays, when it lands on the same Monday as tomorrow", () => {
|
||||
// Sunday 2026-08-30 07:01: "Tomorrow" and "Next week" are both Monday 9:00.
|
||||
const presets = resolveSnoozePresets(localDate(2026, 8, 30, 7, 1));
|
||||
expect(presets.map((preset) => preset.id)).toEqual([
|
||||
"hour",
|
||||
"three-hours",
|
||||
"evening",
|
||||
"tomorrow",
|
||||
]);
|
||||
const tomorrow = new Date(presets.find((preset) => preset.id === "tomorrow")!.snoozedUntil);
|
||||
expect(tomorrow.getDay()).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user