lemmy-ui
lemmy-ui copied to clipboard
Cake days are 1 day off on leap years
Requirements
- [X] This is a bug report, and if not, please post to https://lemmy.ml/c/lemmy_support instead.
- [X] Please check to see if this issue already exists.
- [X] It's a single bug. Do not report multiple bugs in one issue.
- [X] It's a frontend issue, not a backend issue; Otherwise please create an issue on the backend repo instead.
Summary
The current implementation:
import { parseISO, getYear, getDayOfYear } from "date-fns";
export default function isCakeDay(published: string): boolean {
const createDate = parseISO(published);
const currentDate = new Date();
return (
getDayOfYear(createDate) === getDayOfYear(currentDate) &&
getYear(createDate) !== getYear(currentDate)
);
}
Unfortunately, getDayOfYear
counts... well, the day of the year. So on a leap year, this will be 1 day off what is expected. I noticed this as Feddit.dk claims that it is my cake day today, even though it is actually tomorrow. But of course, 2024 is a leap year, so it's 1 day off because of the 29th of February.
Steps to Reproduce
Well it's hard to reproduce as you need to find a user with a cake day tomorrow, but it should be easy enough to understand the bug from the code.
Technical Details
N/A
Lemmy Instance Version
0.19.3
Lemmy Instance URL
https://feddit.dk/
It sounds silly but I think this should probably be fixed for 0.19.4 so that people are updated before all the cake days in June start, there will be many first cake days