JDK-8092803 : Date/time converters use unwanted format patterns
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-07-24
  • Updated: 2015-06-12
  • Resolved: 2014-08-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u40Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
The classes javafx.util.converter.[Date|Time|DateTime]StringConverter use the default format styles (SHORT, MEDIUM, LONG) based on the locale, which causes unwanted formats in many cases.

Since these classes are intended for controls like ComboBox, etc, the style for the default formatters should have been set explicitly to SHORT.

For example, in the en_US locale, a date value will show as "Jan 12, 1985" where "01/12/1985" is probably a more desirable format for an interactive control. I don't expect that end users want to type three letter month names, for example.

A solution can be to add constructors to allow setting the date and time styles, but the bigger question is whether the default styles should be changed so they are set to SHORT automatically. That would break behavior from FX 8, but the alternative would be to add javadoc recommending that the developer should specify SHORT instead of using the default constructor.

Note also that RT-38011 will add an API set to create converters based on the new java.time.Local[Date|Time|DateTime] APIs, and these converters will have SHORT applied explicitly from the beginning.

It is possible that we should close this bug as "will not fix", and add emphasized recommendations in the converter classes to use the RT-38011 API, i.e. to use the new java.time classes instead of java.util.Date and Calendar.
Comments
Changeset: http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/b4880fab246e
13-08-2014

+1
08-08-2014

+1
08-08-2014

+1, but don't forget to get a second +1 for the new API.
05-08-2014

New API in javafx.util.converter: /** * Create a {@link StringConverter} for {@link Date} values, using the * specified {@link DateFormat} date style. * * @param dateStyle the given formatting style. For example, * {@link DateFormat#SHORT} for "M/d/yy" in the US locale. * * @since JavaFX 8u40 */ public DateStringConverter(int dateStyle); /** * Create a {@link StringConverter} for {@link Date} values, using the * specified locale and {@link DateFormat} date style. * * @param locale the given locale. * @param dateStyle the given formatting style. For example, * {@link DateFormat#SHORT} for "M/d/yy" in the US locale. * * @since JavaFX 8u40 */ public DateStringConverter(Locale locale, int dateStyle); /** * Create a {@link StringConverter} for {@link Date} values, using the * specified {@link DateFormat} time style. * * @param timeStyle the given formatting style. For example, * {@link DateFormat#SHORT} for "h:mm a" in the US locale. * * @since JavaFX 8u40 */ public TimeStringConverter(int timeStyle); /** * Create a {@link StringConverter} for {@link Date} values, using the * specified locale and {@link DateFormat} time style. * * @param locale the given locale. * @param timeStyle the given formatting style. For example, * {@link DateFormat#SHORT} for "h:mm a" in the US locale. * * @since JavaFX 8u40 */ public TimeStringConverter(Locale locale, int timeStyle); /** * Create a {@link StringConverter} for {@link Date} values, using specified * {@link DateFormat} styles for date and time. * * @param dateStyle the given formatting style. For example, * {@link DateFormat#SHORT} for "M/d/yy" in the US locale. * @param timeStyle the given formatting style. For example, * {@link DateFormat#SHORT} for "h:mm a" in the US locale. * * @since JavaFX 8u40 */ public DateTimeStringConverter(int dateStyle, int timeStyle); /** * Create a {@link StringConverter} for {@link Date} values, using specified * locale and {@link DateFormat} styles for date and time. * * @param locale the given locale. * @param dateStyle the given formatting style. For example, * {@link DateFormat#SHORT} for "M/d/yy" in the US locale. * @param timeStyle the given formatting style. For example, * {@link DateFormat#SHORT} for "h:mm a" in the US locale. * * @since JavaFX 8u40 */ public DateTimeStringConverter(Locale locale, int dateStyle, int timeStyle);
30-07-2014

Fix for review: http://cr.openjdk.java.net/~leifs/rt38012/webrev.01/ The fix adds two new constructors to each of the three classes, with parameters for date and time styles -- with and without an explicit locale. The default behavior is not changed.
30-07-2014