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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Javen O'Neal-2
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, <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

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

pj.fanning
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: [hidden email]
For additional commands, e-mail: [hidden email]