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

formatDistanceToNow behavior around the month of February #3726

Open
prios-rob-taussig opened this issue Mar 6, 2024 · 0 comments
Open

formatDistanceToNow behavior around the month of February #3726

prios-rob-taussig opened this issue Mar 6, 2024 · 0 comments

Comments

@prios-rob-taussig
Copy link

Just spent a bit of time scratching my head about a unit test failure the other day, and assumed that it had something to do with leap-year. Instead, it looks like February is not considered "about a month":

import { formatDistanceToNow, sub } from 'date-fns';

console.log(formatDistanceToNow(sub(new Date(), { months: 1 })));

// Called on any month besides March:
// "about one month"

// Called during the month of March:
// "29 days"

The above happens because one month ago from a day in March will be 28/29 days, which is less than the cutoff for "about one month" which is:

29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs

Maybe this is working as intended, but personally I think it would be better to decrease the floor to 27 days 23 hrs 59 mins 30 secs(if not explicitly considering whether the target date is February).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant