JodaTime 不会在不匹配的星期几和月份失败

JodaTime doesn't fail on mismatched day of week and month

在下面的代码中,我预计会抛出一个异常,因为星期几与月份中的某一天不匹配。我在 DateTimeFormat Javadocs 中找不到任何关于 "strict" 因此类不匹配而出现的任何方式,但我很困惑,允许这样的错误数据通过。我是否误解了什么,或者这是我应该以其他方式处理的有意识的设计决定?

public static void main(String[] args) {
   DateTimeFormatter DATE_FORMAT_LONG_DATE = //
         DateTimeFormat.forPattern("EEEE, d MMMM yyyy")//
               .withZone(DateTimeZone.forID("Australia/Melbourne"));
   final String text = "Friday, 1 February 2016"; // Wrong.
   final DateTime parsed = DATE_FORMAT_LONG_DATE.parseDateTime(text);
   System.out.println(text);
   System.out.println(DATE_FORMAT_LONG_DATE.print(parsed));
}

并输出:

Friday, 1 February 2016
Friday, 5 February 2016

你说得对,确实如此 - documented(强调我的):

Parsing builds up the resultant instant by 'setting' the value of each parsed field from largest to smallest onto an initial instant, typically 1970-01-01T00:00Z. This design means that day-of-month is set before day-of-week. As such, if both the day-of-month and day-of-week are parsed, and the day-of-week is incorrect, then the day-of-week overrides the day-of-month. This has a side effect if the input is not consistent.

我同意这很不幸 - 但您可以随时重新格式化并检查值是否不同。