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

moment.weekdays() and moment.localeData().weekdays() have different function signature #4783

Closed
andyford opened this issue Sep 20, 2018 · 2 comments

Comments

@andyford
Copy link

andyford commented Sep 20, 2018

Description of the Issue and Steps to Reproduce:

Normally, you can get a list of weekdays like so: moment.weekdays() and if you want them ordered in a localized way (such as Montag/monday as first day of week for Germany) you can do moment.weekdays(true)

But when using the "Accessing locale specific functionality" approach (https://momentjs.com/docs/#/i18n/locale-data/), the .weekdays() method throws the error Uncaught TypeError: m.day is not a function if you try to pass true as the first argument ... localeData = moment.localeData(); localeData.weekdays(true)

And if you omit the first argument to weekdays, then you get the days names in the correct localized language, but they are not in the correct localized order (first day of week is always Sunday [incorrect] but the day name are in the localized language [correct])

What I'd like to do is use an "instance specific locale" (DE) https://momentjs.com/docs/#/i18n/instance-locale/ and then get the weekdays array in a localized way (with montag/monday as the first day of the week), but I can't seem to get around the .weekdays(true) error

moment.locale('en'); // default the locale to English
const localLocale = moment();
localLocale.locale('de'); // set this instance to use German

localLocale.locale(); // --> 'de' (confirm instance is German)
moment.locale(); // --> 'en (confirmglobal is still default/English)

localLocale.localeData().weekdays(); // --> (7) ["Sonntag", "Montag",  ...] (week starts on Sonntag/Sunday but I want Montag/Monday

localLocale.localeData().weekdays(true); // --> Uncaught TypeError: m.day is not a function (was hopeful for Montag/Monday as first day of week

moment.weekdays(true); // --> (7) ["Sunday", "Monday", ...] (still works for default/english)

moment.localeData().weekdays(true); // --> Uncaught TypeError: m.day is not a function

Environment:
This can be replicated in the dev tools console on the momentjs.com/docs site (I tried in Chrome 69/MacOS)

moment.locale('de')
localeData = moment.localeData()
localeData.weekdays(); // starts with 'Sonntag' (Sunday) but should be Montag/Monday
localeData.weekdays(true); // throws error

Other information that may be helpful:

  • The time zone setting of the machine the code is running on
  • The time and date at which the code was run
  • Other libraries in use (TypeScript, Immutable.js, etc)

If you are reporting an issue, please run the following code in the environment you are using and include the output:

console.log( (new Date()).toString())
// Thu Sep 20 2018 14:34:30 GMT+0200 (Central European Summer Time)
console.log((new Date()).toLocaleString())
// 9/20/2018, 2:34:30 PM
console.log( (new Date()).getTimezoneOffset())
// -120
console.log( navigator.userAgent)
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
console.log(moment.version)
// 2.22.2
@mbisurgi-designfreed
Copy link

mbisurgi-designfreed commented Sep 24, 2018

Hi, I have solved this issue and placed a pull request. The bug you were facing I got it to work! Bye

mbisurgi-designfreed added a commit to mbisurgi-designfreed/moment that referenced this issue Sep 24, 2018
@marwahaha
Copy link
Member

This is fixed in 2.24.0 (in this commit: #4553)

I think the issue is a duplicate of #4066 .

Please re-open if you still have issues.

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

3 participants