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

Option to use older behavior of intervalToDuration #3664

Closed
pillowfication opened this issue Jan 12, 2024 · 1 comment
Closed

Option to use older behavior of intervalToDuration #3664

pillowfication opened this issue Jan 12, 2024 · 1 comment

Comments

@pillowfication
Copy link

The intervalToDuration method was changed to remove zeroes.

This change has not yet been reflected in the documentation either.

intervalToDuration({
  start: new Date(1929, 0, 15, 12, 0, 0),
  end: new Date(1968, 3, 4, 19, 5, 0)
})
// => { years: 39, months: 2, days: 20, hours: 7, minutes: 5, seconds: 0 }

I would like a way to keep the zeroes, since I'm trying to use intervalToDuration with formatDuration with zero: true.

formatDuration(
  intervalToDuration({ start: 0, end: 432600000 }), // 5 days and 10 minutes
  {
    format: ['days', 'hours', 'minutes'],
    zero: true,
    locale: { formatDistance: (token, count) => `${count}${token[1].toLowerCase()}` }
  }
)
// Expected -> '5d 0h 10m'
// Actual -> '5d 10m

Another option is to have the FormatDurationOptions.zero option to also apply to undefined values.

@pillowfication
Copy link
Author

just saw duplicate #3658

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