The result of > LocaleUtil.getUserLocale()
should be stored in a local variable at the beginning of the method to reduce the number of get calls, as well as producing inconsistent results if the user locale is modified while formatting a cell value. The UserLocale currently uses per-thread storage so I don't think it's possible to modify while formatting a cell value, but this would be a strange problem to debug if the implementation changed. On Nov 21, 2017 13:11, <[email protected]> wrote: Author: fanningpj Date: Tue Nov 21 21:11:07 2017 New Revision: 1815988 URL: http://svn.apache.org/viewvc?rev=1815988&view=rev Log: remove more uses of Character.toUpperCase Modified: poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java Modified: poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/ poi/ss/format/CellDateFormatter.java?rev=1815988&r1=1815987&r2=1815988& view=diff ============================================================ ================== --- poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java (original) +++ poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java Tue Nov 21 21:11:07 2017 @@ -181,7 +181,6 @@ public class CellDateFormatter extends C boolean doneAm = false; boolean doneMillis = false; - it.first(); for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { @@ -189,12 +188,9 @@ public class CellDateFormatter extends C if (!doneMillis) { Date dateObj = (Date) value; int pos = toAppendTo.length(); - Formatter formatter = new Formatter(toAppendTo, Locale.ROOT); - try { + try (Formatter formatter = new Formatter(toAppendTo, Locale.ROOT)) { long msecs = dateObj.getTime() % 1000; formatter.format(locale, sFmt, msecs / 1000.0); - } finally { - formatter.close(); } toAppendTo.delete(pos, pos + 2); doneMillis = true; @@ -203,11 +199,11 @@ public class CellDateFormatter extends C if (!doneAm) { if (showAmPm) { if (amPmUpper) { - toAppendTo.append(Character.toUpperCase(ch)); + toAppendTo.append(Character. toString(ch).toUpperCase(LocaleUtil.getUserLocale())); if (showM) toAppendTo.append('M'); } else { - toAppendTo.append(Character.toLowerCase(ch)); + toAppendTo.append(Character. toString(ch).toLowerCase(LocaleUtil.getUserLocale())); if (showM) toAppendTo.append('m'); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
