Carsten Hilber Carsten Hilber - 1 year ago 190
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:
["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]

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

Answer Source

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('3/Okt/16','D/MMM/YY').format() //"2016-10-03T00:00:00-07:00"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download