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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with formatDuration function #3803

Closed
riboher opened this issue May 16, 2024 · 2 comments
Closed

Problem with formatDuration function #3803

riboher opened this issue May 16, 2024 · 2 comments

Comments

@riboher
Copy link

riboher commented May 16, 2024

There is an issue with the formatDuration function

The problem

馃捇 Code demonstrating the problem

const duration = formatDuration(
    { seconds: 5000 },
    { format: ['hours', 'minutes'] },
  );
console.log(duration)

馃檨 Actual behavior

Outputting the result of that code gives an empty string. Same happens when trying to reproduce it within the devtools of the documentation website

馃檪 Expected behavior

The expected output should be "1 hour 23 minutes"

Debug information

  • date-fns version: v3.6.0
  • Browser/Node.js version: 123.0.6312.59 (Build oficial) (arm64)/ Node v20.13.1
  • Your timezone: Europe/Madrid
  • Your current time: 15:56h
@rezof
Copy link

rezof commented May 16, 2024

Thats not how formatDistance work.

@riboher
Copy link
Author

riboher commented May 22, 2024

Not sure if it was a mistake but I meant formatDuration, not formatDistance. According to the docs, formatDuration should distribute the value passed in the ranges provided in format,right?

formatDuration(
  {
    years: 2,
    months: 9,
    weeks: 1,
    days: 7,
    hours: 5,
    minutes: 9,
    seconds: 30
  },
  { format: ['months', 'weeks'] }
) === '9 months 1 week'

EDIT: Now I see what you meant, sorry about that 馃う

@riboher riboher closed this as completed May 23, 2024
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