-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Cannot use a locale defined with parent #3883
Cannot use a locale defined with parent #3883
Comments
The following code just ran totally fine for me in chrome console on momentjs.com: moment.defineLocale('absoluta', {
parentLocale : 'fr',
monthsShort : ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jui', 'Jul', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec']
});
moment.locale(false);
moment('08:00:00 01/Avr/17', 'HH:mm:ss DD/MMM/YY', 'absoluta').format('MMM') The only thing I can think is that you don't have the french locale loaded. If that's the case, parenting to it won't work. If you're using a default node.js configuration though, I can't see why that would happen. We load all locales by default in node. |
I have a "standard" nodejs installation, from brew on osx. |
Yeah, I can reproduce this in Node. It must be that we're failing to lazy load in the parent lang in Node. I don't remember quite how that stuff works, so I'm not sure where the bug and fix would be exactly, though. |
Currently looking at this as it's similar to #3626 which I've submitted a PR for. defineLocale returns null if the parent locale is not found. A potential fix would be to lazy load the locale if the parent locale can't be found (see referenced commit). However, this would still fail with the same error this bug details if the parent locale doesn't exist. If the parent locale can't be found, localeFamilies is populated which would be later used to define further locales, but returns null before this occurs. Given this, would some further handling be required if a parent locale can't found/loaded? Currently studying the logic around locale loading, so may revisit with further commits, or if the fix is sufficient I can submit a PR. |
…dded warnings, amended and added test
…dded warning and test
…t is defined. Added warning and test
…t is defined. Added warning and test
…t is defined. Added warning and test
…t is defined. Added test
…t is defined. Added test
…t is defined. Added test
…t is defined. Added test
…t is defined. Added test
Description of the Issue and Steps to Reproduce:
This code is throwing the follwing exception:
If I uncomment the line
moment.localeData('fr');
, it seems to be fixed.Environment:
Moment 2.18.1
NodeJS 7.7.4 on OSX
The text was updated successfully, but these errors were encountered: