Date: Avoid weekday confusion (#5587)

This commit is contained in:
zubiden 2025-02-13 14:28:11 +01:00 committed by Alexander Zinchuk
parent 951378f7c9
commit 8922beda37

View File

@ -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);
}