From 8922beda37b8c64d02d7967cf18083c5a6ac6c00 Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Thu, 13 Feb 2025 14:28:11 +0100 Subject: [PATCH] Date: Avoid weekday confusion (#5587) --- src/util/dates/dateFormat.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/dates/dateFormat.ts b/src/util/dates/dateFormat.ts index 2169c243a..76560fbef 100644 --- a/src/util/dates/dateFormat.ts +++ b/src/util/dates/dateFormat.ts @@ -223,11 +223,12 @@ export function formatHumanDate( return (isUpperFirst || !isShort ? upperFirst : lowerFirst)(lang('Weekday.Yesterday')); } - const weekAgo = new Date(today); - const weekAhead = new Date(today); - weekAgo.setDate(today.getDate() - 7); - weekAhead.setDate(today.getDate() + 7); - if (date >= weekAgo && date <= weekAhead) { + const limitBefore = new Date(today); + limitBefore.setDate(today.getDate() - 6); // Avoid returning same weekday as today + const limitAhead = new Date(today); + limitAhead.setDate(today.getDate() + 6); + + if (date >= limitBefore && date <= limitAhead) { const weekDayString = formatWeekday(lang, date.getDay(), isShort); return (isUpperFirst || !isShort ? upperFirst : lowerFirst)(weekDayString); }