moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.05k stars 728 forks source link

Duration.toISOTime() returns null when hours > 24 #1547

Closed cedvdb closed 7 months ago

cedvdb commented 7 months ago

To Reproduce

const dur = luxon.Duration.fromObject({
      hours: 27,
      minutes: 0
    });
console.log(dur)
console.log(dur.toISOTime({ suppressSeconds: true }) )

Actual vs Expected behavior

Expected: should return "27:00" in this instance. This is not a clock time, this is a duration time, and a duration can be bigger than 24hours.

Actual: null

icambron commented 7 months ago

This is from the docsstring for that function:

Returns an ISO 8601-compliant string representation of this Duration, formatted as a time of day. Note that this will return null if the duration is invalid, negative, or equal to or greater than 24 hours.

You probably just want toISO(). toISOTime() is basically, "pretend this duration is actually a time of day"