commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r590551 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/time/FastDateFormat.java test/org/apache/commons/lang/time/FastDateFormatTest.java
Date Wed, 31 Oct 2007 03:58:52 GMT
Author: bayard
Date: Tue Oct 30 20:58:52 2007
New Revision: 590551

URL: http://svn.apache.org/viewvc?rev=590551&view=rev
Log:
Applying Sebb's test and fix from LANG-368 - fixing it so that FastDateFormat getDateInstance
and getDateTimeInstance continue to work if Locale.getDefault() changes

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java?rev=590551&r1=590550&r2=590551&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java Tue
Oct 30 20:58:52 2007
@@ -281,16 +281,15 @@
         if (timeZone != null) {
             key = new Pair(key, timeZone);
         }
-        if (locale != null) {
-            key = new Pair(key, locale);
+
+        if (locale == null) {
+            locale = Locale.getDefault();
         }
 
+        key = new Pair(key, locale);
+
         FastDateFormat format = (FastDateFormat) cDateInstanceCache.get(key);
         if (format == null) {
-            if (locale == null) {
-                locale = Locale.getDefault();
-            }
-
             try {
                 SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateInstance(style,
locale);
                 String pattern = formatter.toPattern();
@@ -461,16 +460,13 @@
         if (timeZone != null) {
             key = new Pair(key, timeZone);
         }
-        if (locale != null) {
-            key = new Pair(key, locale);
+        if (locale == null) {
+            locale = Locale.getDefault();
         }
+        key = new Pair(key, locale);
 
         FastDateFormat format = (FastDateFormat) cDateTimeInstanceCache.get(key);
         if (format == null) {
-            if (locale == null) {
-                locale = Locale.getDefault();
-            }
-
             try {
                 SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance(dateStyle,
timeStyle,
                         locale);

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java?rev=590551&r1=590550&r2=590551&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java
Tue Oct 30 20:58:52 2007
@@ -132,6 +132,46 @@
         }
     }
 
+    public void test_changeDefault_Locale_DateInstance() {
+        Locale realDefaultLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(Locale.US);
+            FastDateFormat format1 = FastDateFormat.getDateInstance(FastDateFormat.FULL,
Locale.GERMANY);
+            FastDateFormat format2 = FastDateFormat.getDateInstance(FastDateFormat.FULL);
+            Locale.setDefault(Locale.GERMANY);
+            FastDateFormat format3 = FastDateFormat.getDateInstance(FastDateFormat.FULL);
+
+            assertSame(Locale.GERMANY, format1.getLocale());
+            assertSame(Locale.US, format2.getLocale());
+            assertSame(Locale.GERMANY, format3.getLocale());
+            assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1
== format2);
+            assertTrue(format2 != format3);
+
+        } finally {
+            Locale.setDefault(realDefaultLocale);
+        }
+    }
+
+    public void test_changeDefault_Locale_DateTimeInstance() {
+        Locale realDefaultLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(Locale.US);
+            FastDateFormat format1 = FastDateFormat.getDateTimeInstance(FastDateFormat.FULL,
FastDateFormat.FULL, Locale.GERMANY);
+            FastDateFormat format2 = FastDateFormat.getDateTimeInstance(FastDateFormat.FULL,
FastDateFormat.FULL);
+            Locale.setDefault(Locale.GERMANY);
+            FastDateFormat format3 = FastDateFormat.getDateTimeInstance(FastDateFormat.FULL,
FastDateFormat.FULL);
+
+            assertSame(Locale.GERMANY, format1.getLocale());
+            assertSame(Locale.US, format2.getLocale());
+            assertSame(Locale.GERMANY, format3.getLocale());
+            assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1
== format2);
+            assertTrue(format2 != format3);
+
+        } finally {
+            Locale.setDefault(realDefaultLocale);
+        }
+    }
+
     public void test_getInstance_String_TimeZone_Locale() {
         Locale realDefaultLocale = Locale.getDefault();
         TimeZone realDefaultZone = TimeZone.getDefault();



Mime
View raw message