]> granicus.if.org Git - icu/commitdiff
ICU-9771 Update ICU4J to accomodate new currency dates
authorJennifer Chye <jchye@users.noreply.github.com>
Fri, 14 Dec 2012 22:15:57 +0000 (22:15 +0000)
committerJennifer Chye <jchye@users.noreply.github.com>
Fri, 14 Dec 2012 22:15:57 +0000 (22:15 +0000)
X-SVN-Rev: 32972

icu4j/main/classes/core/src/com/ibm/icu/util/Currency.java
icu4j/main/classes/currdata/src/com/ibm/icu/impl/ICUCurrencyMetaInfo.java
icu4j/main/shared/data/icudata.jar
icu4j/main/shared/data/icutzdata.jar

index 293bf022c5be7ecfcd32435a12d86d70e95dd189..ca648e56ab19fa23f73607cf998183f9189e3b29 100644 (file)
@@ -29,6 +29,7 @@ import com.ibm.icu.text.CurrencyDisplayNames;
 import com.ibm.icu.text.CurrencyMetaInfo;
 import com.ibm.icu.text.CurrencyMetaInfo.CurrencyDigits;
 import com.ibm.icu.text.CurrencyMetaInfo.CurrencyFilter;
+import com.ibm.icu.text.CurrencyMetaInfo.CurrencyInfo;
 import com.ibm.icu.util.ULocale.Category;
 
 /**
@@ -159,9 +160,8 @@ public class Currency extends MeasureUnit implements Serializable {
      * @stable ICU 4.0
      */
     public static String[] getAvailableCurrencyCodes(ULocale loc, Date d) {
-        CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
         CurrencyFilter filter = CurrencyFilter.onDate(d).withRegion(loc.getCountry());
-        List<String> list = info.currencies(filter);
+        List<String> list = getTenderCurrencies(filter);
         // Note: Prior to 4.4 the spec didn't say that we return null if there are no results, but 
         // the test assumed it did.  Kept the behavior and amended the spec.
         if (list.isEmpty()) {
@@ -356,7 +356,6 @@ public class Currency extends MeasureUnit implements Serializable {
             return EMPTY_STRING_ARRAY;
         }
         
-        CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
         if (!commonlyUsed) {
             // Behavior change from 4.3.3, no longer sort the currencies
             return getAvailableCurrencyCodes().toArray(new String[0]);
@@ -377,7 +376,7 @@ public class Currency extends MeasureUnit implements Serializable {
         
         // currencies are in region's preferred order when we're filtering on region, which
         // matches our spec
-        List<String> result = info.currencies(filter);
+        List<String> result = getTenderCurrencies(filter);
         
         // No fallback anymore (change from 4.3.3)
         if (result.size() == 0) {
@@ -836,16 +835,16 @@ public class Currency extends MeasureUnit implements Serializable {
 
     private static SoftReference<List<String>> ALL_CODES;
     /*
-     * Returns an unmodifiable String list including all known currency codes
+     * Returns an unmodifiable String list including all known tender currency codes.
      */
     private static synchronized List<String> getAvailableCurrencyCodes() {
         List<String> all = (ALL_CODES == null) ? null : ALL_CODES.get();
         if (all == null) {
-            CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
             // Filter out non-tender currencies which have "from" date set to 9999-12-31
             // CurrencyFilter has "to" value set to 9998-12-31 in order to exclude them
-            CurrencyFilter filter = CurrencyFilter.onDateRange(null, new Date(253373299200000L));
-            all = Collections.unmodifiableList(info.currencies(filter));
+            //CurrencyFilter filter = CurrencyFilter.onDateRange(null, new Date(253373299200000L));
+            CurrencyFilter filter = CurrencyFilter.all();
+            all = Collections.unmodifiableList(getTenderCurrencies(filter));
             ALL_CODES = new SoftReference<List<String>>(all);
         }
         return all;
@@ -894,5 +893,24 @@ public class Currency extends MeasureUnit implements Serializable {
         List<String> allActive = info.currencies(CurrencyFilter.onDateRange(from, to));
         return allActive.contains(code);
     }
+
+    /**
+     * Returns the list of remaining tender currencies after a filter is applied.
+     * @param filter the filter to apply to the tender currencies
+     * @return a list of tender currencies
+     */
+    private static List<String> getTenderCurrencies(CurrencyFilter filter) {
+        CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
+        List<CurrencyInfo> infoList = info.currencyInfo(filter);
+        List<String> list = new ArrayList<String>();
+        for (CurrencyInfo currencyInfo : infoList) {
+            // Non-tender currencies always have a from of MIN_VALUE and a to of MAX_VALUE, so
+            // exclude them.
+            if (currencyInfo.from != Long.MIN_VALUE || currencyInfo.to != Long.MAX_VALUE) {
+                list.add(currencyInfo.code);
+            }
+        }
+        return list;
+    }
 }
 //eof
index 338141c08adbbc2ea6f62da07d3a4a43562c935d..88217040d8b550dc3b34bcb539e20ac6b3beb371 100644 (file)
@@ -147,30 +147,7 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
             return defaultValue;
         }
         int[] values = b.getIntVector();
-        long time = ((long) values[0] << 32) | (((long) values[1]) & MASK);
-        
-        // TODO: remove once errors in CLDR data are fixed.  Or push this into ICU data generation.
-        // The CLDR data parses month as minutes.  We should be getting minutes = 0, so if we detect
-        // that the minute value is nonzero, this means we have bad data and the minute value is really
-        // the month value.
-        GregorianCalendar cal = new GregorianCalendar();
-        cal.setTimeZone(TimeZone.getTimeZone("GMT"));
-        cal.setTimeInMillis(time);
-        int minute = cal.get(Calendar.MINUTE);
-        if (minute != 0) {
-            cal.set(Calendar.MINUTE, 0);
-            cal.set(Calendar.MONTH, minute - 1); // months are 1-based
-            time = cal.getTimeInMillis();
-        }
-        // TODO: generate in CLDR data rather than here, remove endOfDay flag.
-        if (endOfDay) {
-            cal.set(Calendar.HOUR_OF_DAY, 23);
-            cal.set(Calendar.MINUTE, 59);
-            cal.set(Calendar.SECOND, 59);
-            cal.set(Calendar.MILLISECOND, 999);
-            time = cal.getTimeInMillis();
-        }
-        return time;
+        return ((long) values[0] << 32) | (((long) values[1]) & MASK);
     }
 
     // Utility, just because I don't like the n^2 behavior of using list.contains to build a
index f2b60da546d50830d641024a5bae076f590991a3..3c2c45cf9d09f02afed7af1d10bf9f3469862d75 100755 (executable)
@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:8664ebd2785120b69a629e2a3bcb65621037f9caa17b2d2bf9130fc616b01410
-size 9758007
+oid sha256:a5dabb6d00fd76153ed187d1bbfff9afcb633493dd74f0596ffff06a67a1fb4d
+size 9757998
index 278f1c7e54a90ed155da4a636506064dd139b451..7e9f7ec5fb4c9f83d3903b98b9f0b0d8e8dee91c 100755 (executable)
@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:2a2c002e58e4794e6c08b77912d00f403a12cba98fddd0e05811fd947bb23458
-size 97780
+oid sha256:364c990f1ee59ac34c8dfa626e09a3e0f8bb389196e672fefe24e098fafa5575
+size 97776