Skip to content

Conversation

dobon
Copy link
Contributor

@dobon dobon commented Apr 11, 2025

Per discussion #1699 (reply in thread)

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We should not rely on the order of keys in lildur.values
  2. lildur < 0 converts the duration to milliseconds every time. This should be done just once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. is there a more authoritative way? I'll look into this and write a patch.
  2. good catch, will patch.

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duration.js line 794

shiftTo builds up values by looping through orderedUnits.

@dobon dobon requested a review from diesieben07 April 27, 2025 09:56
@diesieben07 diesieben07 merged commit e1d9886 into moment:master Apr 27, 2025
4 checks passed
@diesieben07
Copy link
Collaborator

Thank you!

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

Successfully merging this pull request may close these issues.

3 participants