diff --git a/lemmy-translations b/lemmy-translations index b2de37b3..f0ab81de 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit b2de37b31ea6294fdcd7f41492ea241b62ee9099 +Subproject commit f0ab81deea347c433277a90ae752b10f68473719 diff --git a/src/shared/utils/helpers/is-cake-day.ts b/src/shared/utils/helpers/is-cake-day.ts index 16aa031e..dfa4cde8 100644 --- a/src/shared/utils/helpers/is-cake-day.ts +++ b/src/shared/utils/helpers/is-cake-day.ts @@ -1,11 +1,34 @@ -import { parseISO, getYear, getDayOfYear } from "date-fns"; +import { parseISO, getYear, getDayOfYear, isLeapYear } from "date-fns"; + +const leapDay = getDayOfYear(new Date(2024, 1, 29)); export default function isCakeDay(published: string): boolean { const createDate = parseISO(published); + const createDateDayOfYear = getDayOfYear(createDate); + const isCreateDateLeapYear = isLeapYear(createDate); + const currentDate = new Date(); + let currentDateDayOfYear = getDayOfYear(currentDate); + const isCurrentDateLeapYear = isLeapYear(currentDate); + + if ( + isCreateDateLeapYear && + !isCurrentDateLeapYear && + currentDateDayOfYear >= leapDay + ) { + ++currentDateDayOfYear; + } + + if ( + !isCreateDateLeapYear && + isCurrentDateLeapYear && + createDateDayOfYear >= leapDay + ) { + --currentDateDayOfYear; + } return ( - getDayOfYear(createDate) === getDayOfYear(currentDate) && + createDateDayOfYear === currentDateDayOfYear && getYear(createDate) !== getYear(currentDate) ); }