joda-time icon indicating copy to clipboard operation
joda-time copied to clipboard

Localize the DecimalFormatSeparator in PeriodFormatter appendSecondsWithMillis

Open dektar opened this issue 8 years ago • 1 comments

Key information

  • Joda-Time version: 2.9.4

Problem description

Joda-Time does not use the localized decimal format separator for parsing and printing. Instead, the "." character is hard-coded in several places in PeriodFormatterBuilder.java.

Example: https://github.com/JodaOrg/joda-time/blob/43b17998800f9e4bf076d37cba9e1f63bf00e4e7/src/main/java/org/joda/time/format/PeriodFormatterBuilder.java#L1471

Instead, Joda-Time should use the localized DecimalFormatSeparator, which can be retrieved from DecimalFormatSymbols.getInstance(locale).getDecimalSeparator. https://developer.android.com/reference/java/text/DecimalFormatSymbols.html#getDecimalSeparator() http://docs.oracle.com/javase/6/docs/api/java/text/DecimalFormatSymbols.html#getDecimalSeparator()

Test case

Make a formatter with a Locale: mPeriodFormatter = new PeriodFormatterBuilder() .rejectSignedValues(true) // Applies to all fields .printZeroAlways() // Applies to all fields .appendHours() .appendLiteral(hourMinuteDivider) .minimumPrintedDigits(2) // Applies to minutes and seconds .appendMinutes() .appendLiteral(minuteSecondDivider) .appendSecondsWithMillis() .toFormatter() .withLocale(mLocale); The SecondsWithMillis field should respect the locale. Use Finnish or Turkish and you expect a "," separator, vs English, which expects a "." separator. In fact, both always uses the "." when printing.

dektar avatar Feb 15 '17 18:02 dektar

This is not an unreasonable enhancement request. However, now Java 8 is out, Joda-Time is essentially considered a finished project, and I have no personal plans to work on enhancments,

jodastephen avatar Feb 20 '17 16:02 jodastephen