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

Rounded token values do not bubble up to higher-order tokens. e.g. h:mm format shows '1:60' when duration is 2 hours #84

Closed
oluckyman opened this issue Dec 17, 2017 · 2 comments
Milestone

Comments

@oluckyman
Copy link

moment.duration(
  moment('2017-12-17T02:00:00+00:00') -
  moment('2017-12-17T00:00:30+00:00')
).format('h:mm') // returns: '1:60' instead of '2:00'
@jsmreese
Copy link
Owner

jsmreese commented Dec 17, 2017

Thank you!
This is happening because of the rounding inherent in toLocaleString. I'll check it out.

Similarly failing:

moment.duration({ hours: 2, seconds: -30 }).format("h:mm"); // "1:60"
moment.duration(7170, "seconds").format("h:mm"); // "1:60"
moment.duration(2879, "minutes").format("d[d] h[h]"); // "1d 24h"
moment.duration(335, "hours").format("w[w], d[d]"); // "1w, 7d"
moment.duration({ days: 7, seconds: -30 }).format("w[w] d[d] h:mm", { trim: "all" }); // "6d 23:60"

@jsmreese
Copy link
Owner

Also happens with useSignificantDigits:

moment.duration({ hours: 2, seconds: -60 }).format("h:mm", { precision: 2, useSignificantDigits: true });
// 1:60

@jsmreese jsmreese changed the title h:mm format shows '1:60' when duration is 2 hours Rounded token values do not bubble up to higher-order tokens. e.g. h:mm format shows '1:60' when duration is 2 hours Dec 18, 2017
@jsmreese jsmreese added this to the 2.1.0 milestone Dec 18, 2017
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