Date.js parseExact 与法国文化 [英] Date.js parseExact with french culture

查看:51
本文介绍了Date.js parseExact 与法国文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 svn 主干(修订版 191)中使用最新版本的 date-fr-FR.js.解析似乎在日期和月份名称上失败.

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")

没问题,但是:

Date.parse("vendredi 9 mars 2012")

返回null.

parseExact 也没有帮助:

parseExact doesn't help either:

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

返回空值.

有人遇到过类似的问题吗?是否有更新版本的本地化文件?

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

如果没有人能找到解决方案,也许你可以向我推荐另一个 javascript 日期库.

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

推荐答案

法国文化文件 fr-FR:js 似乎有一些错误.例如星期五的正则表达式显示:

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

这意味着不是ve"或ven"或ven".或ven.dredi"被识别为星期五,但不是vendredi".更准确地说,上面的正则表达式匹配vend"并使redi"不匹配,从而使解析器失败.一周中的所有日子和大多数月份都存在相同的错误.

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.

这篇关于Date.js parseExact 与法国文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆