mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-22 19:01:26 +00:00
Fix leap year issue
This commit is contained in:
parent
ef72c75000
commit
f9f2f17234
2 changed files with 26 additions and 3 deletions
|
@ -1 +1 @@
|
|||
Subproject commit b2de37b31ea6294fdcd7f41492ea241b62ee9099
|
||||
Subproject commit f0ab81deea347c433277a90ae752b10f68473719
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue