fingerpich / jalali-moment

Display, parse, manipulate, validate and convert jalali (Persian, Khorshidi, Shamsi) or Gregorian (Miladi) dates and times.
https://fingerpich.github.io/jalali-moment/
MIT License
436 stars 68 forks source link

question about months name #26

Closed peymanebrahimi closed 7 years ago

peymanebrahimi commented 7 years ago

Hi, This is not an issue. I have a question: What is the use cases of

extend(getPrototypeOf(moment.localeData()),
    { _jMonths: [ "Farvardin"
        , "Ordibehesht"
        , "Khordaad"
        , "Tir"

Because of an issue in angular material 2 datepicker, if your library could set months name in the above code just to Persian names as moment's locale data, it may help on mentioned issue. Thanks again.

fingerpich commented 7 years ago

Hi, What is the problem with the following code?

moment.locale('fa').format('jMMMM');
peymanebrahimi commented 7 years ago

As you helped me with this nice and concise function of returning weekDayNames:

    getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): string[] {
        switch (style) {
            case 'long':
                return jmoment().localeData().weekdays().slice(0);
            case 'short':
                return jmoment().localeData().weekdaysShort().slice(0);
            case 'narrow':
                return jmoment().localeData().weekdaysMin().slice(0);
        }
    }

Is there any similar way to returning months name? I need a consistent way, by calling localeData() return jmoment().localeData().months().slice(0); // must return Persian names

fingerpich commented 7 years ago

Hi, you could use the following code

moment().localeData()._jMonths.slice(0);
moment().localeData()._jMonthsShort.slice(0);
moment().locale('fa').localeData()._jMonths.slice(0);
peymanebrahimi commented 7 years ago

no such functions or properties in typescript. _jMonths is not available on localeData()

fingerpich commented 7 years ago

I will fix it in next version but for now you can cast and use it

(moment().localeData() as any)._jMonths.slice(0);
peymanebrahimi commented 7 years ago

Thank you very much. nice of you as always

AsefDaqiq commented 4 years ago

how can i change the names of the months to Afghanistan's month? is there any way to achieve this functionality?

fingerpich commented 4 years ago

You can find it in the moment documents https://www.tutorialspoint.com/momentjs/momentjs_customization_month_names.htm