ThreeTen / threeten

This project was the home of code used to develop a modern date and time library for JDK8. Development has moved to OpenJDK and a separate backport project, threetenbp.
http://threeten.github.io/
191 stars 37 forks source link

DateTimeFormatter: pattern indicating "narrow" incorrectly printed #38

Closed kleopatra closed 11 years ago

kleopatra commented 12 years ago

.. for Text printouts. Or at least not according to doc, from DateTimeFormatter.pattern(String):

"Text: The text style is determined based on the number of pattern letters used. Less than 4 pattern letters will use the short form. Exactly 4 pattern letters will use the full form. Exactly 5 pattern letters will use the narrow form."

According to this, the expected narrow form for a Day-of-week would be the first letter of the long form, actual is the numeric value. Failing test:

@Test
public void testNarrowWeekOfDayPrint() {
    DateTimeFormatter formatter = DateTimeFormatters.pattern("EEEEE", Locale.ENGLISH);
    assertEquals("W", formatter.print(LocalDateTime.now().with(DAY_OF_WEEK, 3)));
}

Same for month.

jodastephen commented 12 years ago

I think that is because there is no data in the JDK for "narrow" (at least not in JDK 6). Well at least not yet...

masa310 commented 12 years ago

JDK java.text.SimpleDateFormat doesn't (can't) support "narrow" values with 5 pattern letters due to the following spec.

"Text: For formatting, if the number of pattern letters is 4 or more, the full form is used; otherwise a short or abbreviated form is used if available. For parsing, both forms are accepted, independent of the number of pattern letters."

ICU4J SimpleDateFormat has the same spec, but it ignores the spec and supports narrow values with 5 pattern letters.

"(Text): 4 or more pattern letters--use full form, < 4--use short or abbreviated form if one exists." (sample) ""yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 01996.July.10 AD 12:08 PM"

In JDK 8 (b55), a new locale service provider java.util.spi.CalendarDataProvider was added. If JSR 310 needs to support narrow values, it can be extended to support narrow values. But currently no localized resources have narrow values. Both SPI and implementation changes are required.

xuemingshen commented 11 years ago

done.

RogerRiggs commented 11 years ago

Closing since Sherman commented it was done.