You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Javen O'Neal <on...@apache.org> on 2017/11/21 23:42:38 UTC

Re: svn commit: r1815988 - /poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java

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, <fa...@apache.org> 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: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org

Re: svn commit: r1815988 - /poi/trunk/src/java/org/apache/poi/ss/format/CellDateFormatter.java

Posted by "pj.fanning" <fa...@yahoo.com>.
I switched this code to use Locale.ROOT for now.
The current POI code base uses this in more places than the
LocaleUtil.getUserLocale().



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-Dev-f2312866.html

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org