Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cake days are 1 day off on leap years #2441

Closed
4 tasks done
SorteKanin opened this issue Apr 26, 2024 · 1 comment · Fixed by #2453
Closed
4 tasks done

Cake days are 1 day off on leap years #2441

SorteKanin opened this issue Apr 26, 2024 · 1 comment · Fixed by #2453
Labels
bug Something isn't working
Milestone

Comments

@SorteKanin
Copy link

Requirements

  • This is a bug report, and if not, please post to https://lemmy.ml/c/lemmy_support instead.
  • Please check to see if this issue already exists.
  • It's a single bug. Do not report multiple bugs in one issue.
  • 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 SorteKanin added the bug Something isn't working label Apr 26, 2024
@Die4Ever
Copy link
Contributor

Die4Ever commented May 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants