From 782a8325ba4dc933230f15d7373912eaaf05256c Mon Sep 17 00:00:00 2001 From: whekin Date: Tue, 24 Mar 2026 04:16:07 +0400 Subject: [PATCH] fix(bot): correct sleep-aware reminder wording --- apps/bot/src/ad-hoc-notifications.test.ts | 11 +++++++++++ apps/bot/src/ad-hoc-notifications.ts | 13 +++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/apps/bot/src/ad-hoc-notifications.test.ts b/apps/bot/src/ad-hoc-notifications.test.ts index 3c7f125..6b726da 100644 --- a/apps/bot/src/ad-hoc-notifications.test.ts +++ b/apps/bot/src/ad-hoc-notifications.test.ts @@ -576,4 +576,15 @@ describe('formatReminderWhen', () => { }) ).toBe('завтра в 9 утра') }) + + test('keeps actual next-day reminders as tomorrow before 5am', () => { + expect( + formatReminderWhen({ + locale: 'ru', + scheduledForIso: '2026-03-25T05:00:00Z', + timezone: 'Asia/Tbilisi', + now: Temporal.Instant.from('2026-03-24T00:14:00Z') + }) + ).toBe('завтра в 9 утра') + }) }) diff --git a/apps/bot/src/ad-hoc-notifications.ts b/apps/bot/src/ad-hoc-notifications.ts index 6ed0263..d5d4fdf 100644 --- a/apps/bot/src/ad-hoc-notifications.ts +++ b/apps/bot/src/ad-hoc-notifications.ts @@ -170,18 +170,11 @@ function relativeDayLabel(input: { const tomorrow = nowDate.add({ days: 1 }) const dayAfterTomorrow = nowDate.add({ days: 2 }) - const sleepAwareCurrentDate = input.now.hour <= 4 ? nowDate.subtract({ days: 1 }) : nowDate - const sleepAwareTomorrow = sleepAwareCurrentDate.add({ days: 1 }) - const sleepAwareDayAfterTomorrow = sleepAwareCurrentDate.add({ days: 2 }) - - if (targetDate.equals(sleepAwareCurrentDate)) { - return input.locale === 'ru' ? 'сегодня' : 'today' - } - if (targetDate.equals(sleepAwareTomorrow)) { + if (input.now.hour <= 4 && targetDate.equals(nowDate) && input.target.hour <= 12) { return input.locale === 'ru' ? 'завтра' : 'tomorrow' } - if (targetDate.equals(sleepAwareDayAfterTomorrow)) { - return input.locale === 'ru' ? 'послезавтра' : 'the day after tomorrow' + if (targetDate.equals(nowDate)) { + return input.locale === 'ru' ? 'сегодня' : 'today' } if (targetDate.equals(tomorrow)) { return input.locale === 'ru' ? 'завтра' : 'tomorrow'