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

Uppercase function 'undefind' for locale. #4386

Closed
BMK91 opened this Issue Jan 2, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@BMK91
Copy link

BMK91 commented Jan 2, 2018

Hello,
I'm reviewing tutorial
https://momentjs.com/docs/#/i18n/locale-data/

I got an issue for the following:
localeData = moment.localeData();
localeData.longDateFormat();
Uncaught TypeError: Cannot read property 'toUpperCase' of undefined

Also recently found.
localeData.relativeTime();
Uncaught TypeError: Cannot read property 'replace' of undefined

localeData.week();
Uncaught TypeError: Cannot read property 'year' of undefined

Please resolve this issue.
Thank you.

@marwahaha marwahaha added the Bug label Jan 2, 2018

@AlexanderEllis

This comment has been minimized.

Copy link

AlexanderEllis commented Jan 3, 2018

I saw this was marked as a bug, but I did a little digging and think it might not actually be one. Below this link, the docs say that "The returned object has the following methods:"

localeData.longDateFormat(dateFormat);  // returns the full format of abbreviated date-time formats LT, L, LL and so on
localeData.relativeTime(number, withoutSuffix, key, isFuture);  // returns relative time string, key is on of 's', 'm', 'mm', 'h', 'hh', 'd', 'dd', 'M', 'MM', 'y', 'yy'. Single letter when number is 1.
localeData.week(aMoment);  // returns week-of-year of aMoment

Calling these functions without the proper arguments (like localeData.longDateFormat();) does indeed throw these typeErrors, as the dateFormat would not be provided. Maybe not the most elegant result, but is this what we would expect?

That being said, I also missed this in the docs at first glance and spent some time digging through the code, as the method signatures seem to imply you can call these without arguments. I only noticed it after returning to the docs and scrolling down to see if what I found matched anything there.

Looks like the method signatures in the docs could use some updating. If that sounds about right, I can go ahead and update these ones as needed.

The only thing I'm not sure about is some of the methods that seem to behave differently with or without arguments. For instance, moment.localeData().months() returns all months, but it seems that moment.localeData().months(moment()) is different, in that it just returns the current month.

@marwahaha

This comment has been minimized.

Copy link
Member

marwahaha commented Apr 4, 2018

Yea, this looks like a documentation issue. Thanks @AlexanderEllis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment