-
Notifications
You must be signed in to change notification settings - Fork 761
Only add minus sign on largest unit of negative durations #1701
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
Only add minus sign on largest unit of negative durations #1701
Conversation
src/impl/formatter.js
Outdated
default: | ||
return null; | ||
} | ||
}, | ||
tokenToString = (lildur) => (token) => { | ||
const mapped = tokenToField(token); | ||
if (mapped) { | ||
return this.num(lildur.get(mapped), token.length); | ||
const inversionFactor = lildur < 0 && mapped !== Object.keys(lildur.values)[0] ? -1 : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We should not rely on the order of keys in
lildur.values
lildur < 0
converts the duration to milliseconds every time. This should be done just once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- is there a more authoritative way? I'll look into this and write a patch.
- good catch, will patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there is an easy way. We'd have to find the index in orderedUnits
. shiftTo
happens here every time, can you check if that has a defined key order? But even if it does, it feels wrong to rely on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shiftTo
builds up values
by looping through orderedUnits
.
Thank you! |
Per discussion #1699 (reply in thread)