Browse Source

Clarify requirements of strict date formats. (#29090)

Closes #29014
Adrien Grand 7 years ago
parent
commit
0755ff425f

+ 12 - 6
docs/reference/mapping/params/format.asciidoc

@@ -44,12 +44,18 @@ http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html[i
 [[built-in-date-formats]]
 ==== Built In Formats
 
-Most of the below dates have a `strict` companion dates, which means, that
-year, month and day parts of the week must have prepending zeros in order
-to be valid. This means, that a date like `5/11/1` would not be valid, but
-you would need to specify the full date, which would be `2005/11/01` in this
-example. So instead of `date_optional_time` you would need to specify
-`strict_date_optional_time`.
+Most of the below formats have a `strict` companion format, which means that
+year, month and day parts of the week must use respectively 4, 2 and 2 digits
+exactly, potentially prepending zeros. For instance a date like `5/11/1` would
+be considered invalid and would need to be rewritten to `2005/11/01` to be
+accepted by the date parser.
+
+To use them, you need to prepend `strict_` to the name of the date format, for
+instance `strict_date_optional_time` instead of `date_optional_time`.
+
+These strict date formats are especially useful when
+<<date-detection,date fields are dynamically mapped>> in order to make sure to
+not accidentally map irrelevant strings as dates.
 
 The following tables lists all the defaults ISO formats supported:
 

+ 1 - 1
server/src/main/java/org/joda/time/format/StrictISODateTimeFormat.java

@@ -27,7 +27,7 @@ import java.util.Set;
  * class is named ISODatetimeFormat
  *
  * However there has been done one huge modification in several methods, which forces the date
- * year to be at least n digits, so that a year like "5" is invalid and must be "0005"
+ * year to be exactly n digits, so that a year like "5" is invalid and must be "0005"
  *
  * All methods have been marked with an "// ES change" commentary
  *