lemmy-ui icon indicating copy to clipboard operation
lemmy-ui copied to clipboard

Cake days are 1 day off on leap years

Open SorteKanin opened this issue 2 months ago • 1 comments

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/

SorteKanin avatar Apr 26 '24 16:04 SorteKanin

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

Die4Ever avatar May 06 '24 02:05 Die4Ever