feat: offer this morning and this afternoon as schedule times while they are ahead #1390

This commit is contained in:
Linus Rath
2026-10-29 14:34:00 +01:00
parent 69d2f35d78
commit 828d0acc0b
31 changed files with 85 additions and 3 deletions
+15
View File
@@ -24,4 +24,19 @@ describe('schedulePresets', () => {
const presets = schedulePresets(local(2026, 10, 12, 9));
expect(presets.find((p) => p.key === 'monday_morning')?.date.getTime()).toBe(local(2026, 10, 19, 8).getTime());
});
it('offers this morning and afternoon after midnight, while they are ahead (#1390)', () => {
// Thursday 2026-10-15, 01:30
const presets = schedulePresets(local(2026, 10, 15, 1, 30));
expect(presets.slice(0, 3).map((p) => [p.key, p.date.getTime()])).toEqual([
['this_morning', local(2026, 10, 15, 8).getTime()],
['this_afternoon', local(2026, 10, 15, 13).getTime()],
['tomorrow_morning', local(2026, 10, 16, 8).getTime()],
]);
});
it('drops a time of today that is past or about to be', () => {
expect(schedulePresets(local(2026, 10, 15, 9)).map((p) => p.key)[0]).toBe('this_afternoon');
expect(schedulePresets(local(2026, 10, 15, 12, 58)).map((p) => p.key)[0]).toBe('tomorrow_morning');
});
});
+12 -3
View File
@@ -1,4 +1,4 @@
export type SchedulePresetKey = 'tomorrow_morning' | 'tomorrow_afternoon' | 'monday_morning';
export type SchedulePresetKey = 'this_morning' | 'this_afternoon' | 'tomorrow_morning' | 'tomorrow_afternoon' | 'monday_morning';
export interface SchedulePreset {
key: SchedulePresetKey;
@@ -12,16 +12,25 @@ function at(base: Date, daysAhead: number, hour: number): Date {
return date;
}
/** How far ahead a time for today must be to be offered, so it is not past by the click. */
const TODAY_LEAD_MS = 5 * 60_000;
/**
* One-click times for "Schedule send", like other mail clients offer:
* tomorrow at 8:00 and 13:00, and next Monday at 8:00. Monday is left out
* when it is tomorrow anyway (on a Sunday).
* when it is tomorrow anyway (on a Sunday). Today's 8:00 and 13:00 come
* first while they are still ahead, so a message written after midnight can
* go out the same morning (#1390).
*/
export function schedulePresets(now: Date = new Date()): SchedulePreset[] {
const presets: SchedulePreset[] = [
{ key: 'this_morning' as const, date: at(now, 0, 8) },
{ key: 'this_afternoon' as const, date: at(now, 0, 13) },
].filter((preset) => preset.date.getTime() - now.getTime() >= TODAY_LEAD_MS);
presets.push(
{ key: 'tomorrow_morning', date: at(now, 1, 8) },
{ key: 'tomorrow_afternoon', date: at(now, 1, 13) },
];
);
const daysToMonday = ((8 - now.getDay()) % 7) || 7;
if (daysToMonday > 1) presets.push({ key: 'monday_morning', date: at(now, daysToMonday, 8) });
return presets;
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "جدولة الإرسال",
"schedule_send_description": "اختر متى يجب على الخادم إرسال هذه الرسالة.",
"schedule_preset": {
"this_morning": "هذا الصباح",
"this_afternoon": "بعد ظهر اليوم",
"tomorrow_morning": "صباح الغد",
"tomorrow_afternoon": "ظهر الغد",
"monday_morning": "صباح الاثنين"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Programa l'enviament",
"schedule_send_description": "Trieu quan ha d'alliberar el servidor aquest missatge.",
"schedule_preset": {
"this_morning": "Aquest matí",
"this_afternoon": "Aquesta tarda",
"tomorrow_morning": "Demà al matí",
"tomorrow_afternoon": "Demà a la tarda",
"monday_morning": "Dilluns al matí"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Naplánovat odeslání",
"schedule_send_description": "Vyberte, kdy má server tuto zprávu odeslat.",
"schedule_preset": {
"this_morning": "Dnes ráno",
"this_afternoon": "Dnes odpoledne",
"tomorrow_morning": "Zítra ráno",
"tomorrow_afternoon": "Zítra odpoledne",
"monday_morning": "V pondělí ráno"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Planlæg afsendelse",
"schedule_send_description": "Vælg hvornår serveren skal frigive denne besked.",
"schedule_preset": {
"this_morning": "I dag formiddag",
"this_afternoon": "I eftermiddag",
"tomorrow_morning": "I morgen formiddag",
"tomorrow_afternoon": "I morgen eftermiddag",
"monday_morning": "Mandag formiddag"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Senden planen",
"schedule_send_description": "Wählen Sie, wann der Server diese Nachricht freigeben soll.",
"schedule_preset": {
"this_morning": "Heute früh",
"this_afternoon": "Heute Nachmittag",
"tomorrow_morning": "Morgen früh",
"tomorrow_afternoon": "Morgen Nachmittag",
"monday_morning": "Montag früh"
+2
View File
@@ -929,6 +929,8 @@
"schedule_send": "Schedule send",
"schedule_send_description": "Choose when the server should release this message.",
"schedule_preset": {
"this_morning": "This morning",
"this_afternoon": "This afternoon",
"tomorrow_morning": "Tomorrow morning",
"tomorrow_afternoon": "Tomorrow afternoon",
"monday_morning": "Monday morning"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Programar envío",
"schedule_send_description": "Elige cuándo debe liberar el servidor este mensaje.",
"schedule_preset": {
"this_morning": "Esta mañana",
"this_afternoon": "Esta tarde",
"tomorrow_morning": "Mañana por la mañana",
"tomorrow_afternoon": "Mañana por la tarde",
"monday_morning": "El lunes por la mañana"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Ajasta saatmine",
"schedule_send_description": "Vali, millal server peaks selle sõnumi välja saatma.",
"schedule_preset": {
"this_morning": "Täna hommikul",
"this_afternoon": "Täna pärastlõunal",
"tomorrow_morning": "Homme hommikul",
"tomorrow_afternoon": "Homme pärastlõunal",
"monday_morning": "Esmaspäeva hommikul"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "زمان‌بندی ارسال",
"schedule_send_description": "زمان انتشار پیام توسط سرور را انتخاب کنید.",
"schedule_preset": {
"this_morning": "امروز صبح",
"this_afternoon": "امروز بعدازظهر",
"tomorrow_morning": "فردا صبح",
"tomorrow_afternoon": "فردا بعدازظهر",
"monday_morning": "دوشنبه صبح"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Planifier l’envoi",
"schedule_send_description": "Choisissez quand le serveur doit libérer ce message.",
"schedule_preset": {
"this_morning": "Ce matin",
"this_afternoon": "Cet après-midi",
"tomorrow_morning": "Demain matin",
"tomorrow_afternoon": "Demain après-midi",
"monday_morning": "Lundi matin"
+2
View File
@@ -892,6 +892,8 @@
"schedule_send": "תזמן שליחה",
"schedule_send_description": "בחר מתי השרת צריך לשחרר הודעה זו.",
"schedule_preset": {
"this_morning": "הבוקר",
"this_afternoon": "היום אחר הצהריים",
"tomorrow_morning": "מחר בבוקר",
"tomorrow_afternoon": "מחר אחר הצהריים",
"monday_morning": "יום שני בבוקר"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Késleltetett küldés",
"schedule_send_description": "Válaszd ki, mikor küldje el a szerver az üzenetet.",
"schedule_preset": {
"this_morning": "Ma reggel",
"this_afternoon": "Ma délután",
"tomorrow_morning": "Holnap reggel",
"tomorrow_afternoon": "Holnap délután",
"monday_morning": "Hétfő reggel"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Programma invio",
"schedule_send_description": "Scegli quando il server deve rilasciare questo messaggio.",
"schedule_preset": {
"this_morning": "Stamattina",
"this_afternoon": "Oggi pomeriggio",
"tomorrow_morning": "Domattina",
"tomorrow_afternoon": "Domani pomeriggio",
"monday_morning": "Lunedì mattina"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "送信を予約",
"schedule_send_description": "サーバーがこのメッセージを送信する日時を選択します。",
"schedule_preset": {
"this_morning": "今朝",
"this_afternoon": "今日の午後",
"tomorrow_morning": "明日の朝",
"tomorrow_afternoon": "明日の午後",
"monday_morning": "月曜日の朝"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "보내기 예약",
"schedule_send_description": "서버가 이 메시지를 보낼 시간을 선택하세요.",
"schedule_preset": {
"this_morning": "오늘 아침",
"this_afternoon": "오늘 오후",
"tomorrow_morning": "내일 오전",
"tomorrow_afternoon": "내일 오후",
"monday_morning": "월요일 오전"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Ieplānot sūtīšanu",
"schedule_send_description": "Izvēlieties, kad serverim jānosūta šis ziņojums.",
"schedule_preset": {
"this_morning": "Šorīt",
"this_afternoon": "Šodien pēcpusdienā",
"tomorrow_morning": "Rīt no rīta",
"tomorrow_afternoon": "Rīt pēcpusdienā",
"monday_morning": "Pirmdien no rīta"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Хуваарь илгээх",
"schedule_send_description": "Сервер энэ мессежийг хэзээ гаргахыг сонгоно уу.",
"schedule_preset": {
"this_morning": "Өнөө өглөө",
"this_afternoon": "Өнөөдөр үдээс хойш",
"tomorrow_morning": "Маргааш өглөө",
"tomorrow_afternoon": "Маргааш үдээс хойш",
"monday_morning": "Даваа гарагийн өглөө"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Planlegg sending",
"schedule_send_description": "Velg når serveren skal sende denne meldingen.",
"schedule_preset": {
"this_morning": "I dag tidlig",
"this_afternoon": "I ettermiddag",
"tomorrow_morning": "I morgen tidlig",
"tomorrow_afternoon": "I morgen ettermiddag",
"monday_morning": "Mandag morgen"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Verzenden plannen",
"schedule_send_description": "Kies wanneer de server dit bericht moet vrijgeven.",
"schedule_preset": {
"this_morning": "Vanochtend",
"this_afternoon": "Vanmiddag",
"tomorrow_morning": "Morgenochtend",
"tomorrow_afternoon": "Morgenmiddag",
"monday_morning": "Maandagochtend"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Zaplanuj wysyłkę",
"schedule_send_description": "Wybierz, kiedy serwer ma wysłać tę wiadomość.",
"schedule_preset": {
"this_morning": "Dziś rano",
"this_afternoon": "Dziś po południu",
"tomorrow_morning": "Jutro rano",
"tomorrow_afternoon": "Jutro po południu",
"monday_morning": "W poniedziałek rano"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Agendar envio",
"schedule_send_description": "Escolha quando o servidor deve liberar esta mensagem.",
"schedule_preset": {
"this_morning": "Esta manhã",
"this_afternoon": "Esta tarde",
"tomorrow_morning": "Amanhã de manhã",
"tomorrow_afternoon": "Amanhã à tarde",
"monday_morning": "Segunda de manhã"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Programează trimiterea",
"schedule_send_description": "Alegeți momentul în care serverul ar trebui să transmită acest mesaj.",
"schedule_preset": {
"this_morning": "Azi dimineață",
"this_afternoon": "Azi după-amiază",
"tomorrow_morning": "Mâine dimineață",
"tomorrow_afternoon": "Mâine după-amiază",
"monday_morning": "Luni dimineață"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Запланировать отправку",
"schedule_send_description": "Выберите, когда сервер должен отправить это сообщение.",
"schedule_preset": {
"this_morning": "Сегодня утром",
"this_afternoon": "Сегодня днём",
"tomorrow_morning": "Завтра утром",
"tomorrow_afternoon": "Завтра днём",
"monday_morning": "В понедельник утром"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Naplánovať odoslanie",
"schedule_send_description": "Vyberte, kedy má server túto správu odoslať.",
"schedule_preset": {
"this_morning": "Dnes ráno",
"this_afternoon": "Dnes popoludní",
"tomorrow_morning": "Zajtra ráno",
"tomorrow_afternoon": "Zajtra popoludní",
"monday_morning": "V pondelok ráno"
+2
View File
@@ -1154,6 +1154,8 @@
"schedule_send": "กำหนดเวลาส่ง",
"schedule_send_description": "เลือกเวลาที่ต้องการให้เซิร์ฟเวอร์ส่งข้อความนี้",
"schedule_preset": {
"this_morning": "เช้านี้",
"this_afternoon": "บ่ายนี้",
"tomorrow_morning": "เช้าวันพรุ่งนี้",
"tomorrow_afternoon": "บ่ายวันพรุ่งนี้",
"monday_morning": "เช้าวันจันทร์"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Göndermeyi zamanla",
"schedule_send_description": "Sunucunun bu iletiyi ne zaman göndereceğini seçin.",
"schedule_preset": {
"this_morning": "Bu sabah",
"this_afternoon": "Bu öğleden sonra",
"tomorrow_morning": "Yarın sabah",
"tomorrow_afternoon": "Yarın öğleden sonra",
"monday_morning": "Pazartesi sabah"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "Запланувати надсилання",
"schedule_send_description": "Виберіть, коли сервер має надіслати це повідомлення.",
"schedule_preset": {
"this_morning": "Сьогодні вранці",
"this_afternoon": "Сьогодні вдень",
"tomorrow_morning": "Завтра вранці",
"tomorrow_afternoon": "Завтра вдень",
"monday_morning": "У понеділок вранці"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "排程寄送",
"schedule_send_description": "選擇伺服器要在何時送出這封郵件。",
"schedule_preset": {
"this_morning": "今天早上",
"this_afternoon": "今天下午",
"tomorrow_morning": "明天上午",
"tomorrow_afternoon": "明天下午",
"monday_morning": "星期一上午"
+2
View File
@@ -927,6 +927,8 @@
"schedule_send": "计划发送",
"schedule_send_description": "选择服务器应何时发送此邮件。",
"schedule_preset": {
"this_morning": "今天早上",
"this_afternoon": "今天下午",
"tomorrow_morning": "明天上午",
"tomorrow_afternoon": "明天下午",
"monday_morning": "周一上午"