We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug
Creating a duration using a decimal hour then using toFormat produces an incorrect result
toFormat
The inputs we've seen wrong so far are 2.4 and 5.3
2.4
5.3
To Reproduce
luxon.Duration.fromObject({hour: 2.4}).toFormat('hh:mm') returns "02:23" luxon.Duration.fromObject({hour: 5.3}).toFormat('hh:mm') returns "05:17"
luxon.Duration.fromObject({hour: 2.4}).toFormat('hh:mm')
"02:23"
luxon.Duration.fromObject({hour: 5.3}).toFormat('hh:mm')
"05:17"
Actual vs Expected behavior
2.4 hours is 02:24 5.3 hours is 05:18
Desktop (please complete the following information):
Additional context
Converting to different units from hours produces correct results
luxon.Duration.fromObject({minute: 2.4 * 60}).toFormat('hh:mm') = "02:24" luxon.Duration.fromObject({second: 2.4 * 60 * 60}).toFormat('hh:mm') = "02:24" luxon.Duration.fromObject({hour: 2.4}).shiftTo('seconds').toFormat('hh:mm') = "02:24" luxon.Duration.fromMillis(8640000).toFormat('hh:mm') = "02:24"
luxon.Duration.fromObject({minute: 2.4 * 60}).toFormat('hh:mm')
"02:24"
luxon.Duration.fromObject({second: 2.4 * 60 * 60}).toFormat('hh:mm')
luxon.Duration.fromObject({hour: 2.4}).shiftTo('seconds').toFormat('hh:mm')
luxon.Duration.fromMillis(8640000).toFormat('hh:mm')
Shifting to hours also produces the wrong result
luxon.Duration.fromObject({minute: 2.4 * 60}).shiftTo('hour').toFormat('hh:mm') = "02:23"
luxon.Duration.fromObject({minute: 2.4 * 60}).shiftTo('hour').toFormat('hh:mm')
The durations still produce the same valueOf
luxon.Duration.fromObject({hour: 2.4}).valueOf() = 8640000 luxon.Duration.fromObject({minute: 2.4 * 60}).valueOf() = 8640000
luxon.Duration.fromObject({hour: 2.4}).valueOf()
8640000
luxon.Duration.fromObject({minute: 2.4 * 60}).valueOf()
The text was updated successfully, but these errors were encountered:
This is some kind of floating point math problem:
Duration.fromObject({hour: 2.4}).shiftTo("hours", "minutes").toObject() //=> { hours: 2, minutes: 23.999999999999993 }
Then mm formats 23 because it's not quite 24. I'd definitely accept a fix for this
mm
Sorry, something went wrong.
Addressed by #1078
@bluSCALE4 Cool. I'll get this into the next version. I'll probably add a few more test cases just to make sure it doesn't break anything new
fix for #1070
6f86ca3
Fixed in 2.2.0
No branches or pull requests
Describe the bug
Creating a duration using a decimal hour then using
toFormat
produces an incorrect resultThe inputs we've seen wrong so far are
2.4
and5.3
To Reproduce
luxon.Duration.fromObject({hour: 2.4}).toFormat('hh:mm')
returns"02:23"
luxon.Duration.fromObject({hour: 5.3}).toFormat('hh:mm')
returns"05:17"
Actual vs Expected behavior
2.4 hours is 02:24
5.3 hours is 05:18
Desktop (please complete the following information):
Additional context
Converting to different units from hours produces correct results
luxon.Duration.fromObject({minute: 2.4 * 60}).toFormat('hh:mm')
="02:24"
luxon.Duration.fromObject({second: 2.4 * 60 * 60}).toFormat('hh:mm')
="02:24"
luxon.Duration.fromObject({hour: 2.4}).shiftTo('seconds').toFormat('hh:mm')
="02:24"
luxon.Duration.fromMillis(8640000).toFormat('hh:mm')
="02:24"
Shifting to hours also produces the wrong result
luxon.Duration.fromObject({minute: 2.4 * 60}).shiftTo('hour').toFormat('hh:mm')
="02:23"
The durations still produce the same valueOf
luxon.Duration.fromObject({hour: 2.4}).valueOf()
=8640000
luxon.Duration.fromObject({minute: 2.4 * 60}).valueOf()
=8640000
The text was updated successfully, but these errors were encountered: