Carsten Hilber Carsten Hilber - 1 month ago 24
Javascript Question

moment js sometimes has moment.monthsShort() with period (dot) in german locale

I have written a JIRA plugin which uses moment js to format and parse dates.
On some installations I am getting a strange behaviour when moment.js has the short names with a trailing period.

Where does moment.js get the shortNames from? How do I achieve to always get the same short names?

At the moment, the parse of a date like 3/Okt/16 fails on my Ubuntu instance, but works on Mac. Where 3/Okt./16 seems to work on both.

Since the field is populated through Java SimpleDateFormat, I have no chance to change the incoming format.

Examples called from The same Browser:

JIRA Server hosted on MacOS:
moment.monthsShort()
["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]

JIRA Server hosted on Ubuntu:
moment.monthsShort()
["Jan.", "Febr.", "Mrz.", "Apr.", "Mai", "Jun.", "Jul.", "Aug.", "Sept.", "Okt.", "Nov.", "Dez."]

Answer

Basically, I think your best bet is to write some code that checks if moment is version 2.13 or greater, and overwrites with the old locale data if it is. The following code should do the trick:

if(moment.version.split('.')[1] > 12) 
{ 
    moment.updateLocale('de',{
    monthsShort:'Jan_Febr_Mrz_Apr_Mai_Jun_Jul_Aug_Sept_Okt_Nov_Dez'.split('_')

    });
}
moment('3/Okt/16','D/MMM/YY').format() //"2016-10-03T00:00:00-07:00"
Comments