yyyy-mm-dd 格式的日期不会抛出错误

Date in yyyyy-mm-dd format not throwing error

好吧,这可能看起来很奇怪,但我看到,在将字符串转换为日期时,值 20155-10-10 没有抛出错误,指出无效日期。

使用的函数如下

fn-bea:date-from-string-with-format("MM/dd/yyyy",'10/10/20155')

上面的函数返回日期 20155-10-10,当上面的字符串被传递并且也被模式验证时。该字段声明为 xs:date

类型

函数的原型是

fn-bea:date-from-string-with-format($format as xs:string?, $dateString as xs:string?) as xs:date?

函数用法和示例请参考link http://docs.oracle.com/cd/E13167_01/aldsp/docs25/xquery/extensions.html#wp1297249

这是预期的并记录在案的行为,尽管确实令人惊讶。

OSB 日期模式

Oracle documentation on fn-bea:date-from-string-with-format(...) 包含以下关于日期模式的注释(我添加的突出显示):

You can construct date and time patterns using standard Java class symbols. [...] Repeat each symbol to match the maximum number of characters required to represent the actual value. [...]

因此,OSB 使用默认的 Java 日期模式,并且 YYYY 将日期设置为要求 至少 四位数年份声明,但允许任意更长的。例如,MM/dd/yyyy 匹配 23/02/201423/02/20155;但不是 23/02/42.

Java 日期模式

查看 Java specifications 来验证这一点,即使是最后日期(42 年)也是允许的:

For parsing, if the number of pattern letters is more than 2, the year is interpreted literally, regardless of the number of digits. So using the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.

可能是 OSB 使用了自己的解析规则以及 Java 日期 class 符号。


我没有根据 OSB 验证使用了哪一个,但是两个规范 do 都允许 YYYY.

使用五位数的年份