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

Incorrect Output from formatDistanceToNowStrict or formatDistanceToNow for Week Duration #3753

Open
zcmgyu opened this issue Apr 2, 2024 · 1 comment

Comments

@zcmgyu
Copy link

zcmgyu commented Apr 2, 2024

Description:

When using the formatDistanceToNowStrict function from date-fns to calculate the distance to the current time from a date that is exactly one week ago, the output is incorrectly displayed as “7 days” instead of “1 week”.

Steps to Reproduce:

  1. Subtract 7 days worth of seconds from the current date to simulate a date that is one week in the past.
  2. Use the formatDistanceToNowStrict function to calculate the distance to now from this past date.
  3. Observe the output logged to the console.

Expected Result:

The output should be “1 week” to accurately reflect the duration of one week.

Actual Result:

The output is “7 days”, which does not align with the expected week-based formatting.

Code to Reproduce:

const date = subSeconds(new Date(), 7 * 24 * 60 * 60);
const output = formatDistanceToNowStrict(date);
console.log('DEBUG output: ', output);
// DEBUG output:  7 days

Additional Information:

date-fns: 3.6.0

@brian890809
Copy link

brian890809 commented Apr 9, 2024

judging from the documentation, it seems right to have the output as "7 days" instead of "1 week".

Copied for reference:

1 ... 29 days [1..29] days

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

2 participants