Date.js parseExact with french culture

拟墨画扇 提交于 2020-01-06 03:41:35

问题


I'm using the last build of date-fr-FR.js in the svn trunk (rev 191). The parsing seems to fail on days and months names.

Date.parse("9 3 2012")

is ok, but:

Date.parse("vendredi 9 mars 2012")

returns null.

parseExact doesn't help either:

Date.parseExact("vendredi 9 mars 2012", "dddd d MMMM yyyy")

returns null.

Anyone faced a similar issue ? Is there a more recent version of the localized files ?

Maybe you could recommend me another javascript date library if nobody can find a solution.


回答1:


The French culture file fr-FR:js appears to have a few of bugs. For example the regular expression for Friday shows:

/^ve(n(.(dredi)?)?)?/i

This means than either "ve" or "ven" or "ven." or "ven.dredi" are recognized as Friday but not "vendredi". More precisely the above regex matches the "vend" and leaves "redi" unmatched, thus failing the parser. The same bug is present for all days of the week and most months.

To fix this you could replace the above regular expression with:

/^ve(n(\.|(dredi)?)?)?/i

Adding the alternate "|" after the any character ".". I have also escaped the dot because it should not match "any" character but just the dot though this would not fail your test case.



来源:https://stackoverflow.com/questions/9632928/date-js-parseexact-with-french-culture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!