[DOC ONLY] RT-35758: [DatePicker] When typing year as YY, should DatePicker choose nearest century or current one? diff -r 3a65c617bbe4 -r 75eba40fbc29 modules/controls/src/main/java/javafx/scene/control/DatePicker.java --- a/modules/controls/src/main/java/javafx/scene/control/DatePicker.java Mon Feb 24 19:07:48 2014 -0800 +++ b/modules/controls/src/main/java/javafx/scene/control/DatePicker.java Wed Feb 26 13:28:08 2014 -0800 @@ -359,6 +359,35 @@ * }); * * + *
The default base year for parsing input containing only two digits for + * the year is 2000 (see {@link java.time.format.DateTimeFormatter}). This + * default is not useful for allowing a person's date of birth to be typed. + * The following example modifies the converter's fromString() method to + * allow a two digit year for birth dates up to 99 years in the past. + *
+ * @Override public LocalDate fromString(String text) {
+ * if (text != null && !text.isEmpty()) {
+ * Locale locale = Locale.getDefault(Locale.Category.FORMAT);
+ * Chronology chrono = datePicker.getChronology();
+ * String pattern =
+ * DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT,
+ * null, chrono, locale);
+ * String prePattern = pattern.substring(0, pattern.indexOf("y"));
+ * String postPattern = pattern.substring(pattern.lastIndexOf("y")+1);
+ * int baseYear = LocalDate.now().getYear() - 99;
+ * DateTimeFormatter df = new DateTimeFormatterBuilder()
+ * .parseLenient()
+ * .appendPattern(prePattern)
+ * .appendValueReduced(ChronoField.YEAR, 2, 2, baseYear)
+ * .appendPattern(postPattern)
+ * .toFormatter();
+ * return LocalDate.from(chrono.date(df.parse(text)));
+ * } else {
+ * return null;
+ * }
+ * }
+ *
+ *
* @see javafx.scene.control.ComboBox#converterProperty
*/
public final ObjectProperty