]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/TimeZoneNameProviderICU.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / localespi / src / com / ibm / icu / impl / javaspi / util / TimeZoneNameProviderICU.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2008-2012, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.impl.javaspi.util;
8
9 import java.util.Locale;
10 import java.util.TimeZone;
11
12 import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
13 import com.ibm.icu.text.TimeZoneNames;
14 import com.ibm.icu.text.TimeZoneNames.NameType;
15
16 public class TimeZoneNameProviderICU extends java.util.spi.TimeZoneNameProvider {
17
18     @Override
19     public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {
20         String dispName = null;
21         boolean[] isSystemID = new boolean[1];
22         String canonicalID = com.ibm.icu.util.TimeZone.getCanonicalID(ID, isSystemID);
23         if (isSystemID[0]) {
24             long date = System.currentTimeMillis();
25             TimeZoneNames tznames = TimeZoneNames.getInstance(ICULocaleServiceProvider.toULocaleNoSpecialVariant(locale));
26
27             {
28                 // Workaround for Java bug. Java needs all 4 names available at the same time.
29                 // 2012-10-09 yoshito
30                 String lstd = tznames.getDisplayName(canonicalID, NameType.LONG_STANDARD, date);
31                 String ldst = tznames.getDisplayName(canonicalID, NameType.LONG_DAYLIGHT, date);
32                 String sstd = tznames.getDisplayName(canonicalID, NameType.SHORT_STANDARD, date);
33                 String sdst = tznames.getDisplayName(canonicalID, NameType.SHORT_DAYLIGHT, date);
34
35                 if (lstd != null && ldst != null && sstd != null && sdst != null) {
36                     switch (style) {
37                     case TimeZone.LONG:
38                         dispName = daylight ? ldst : lstd;
39                         break;
40                     case TimeZone.SHORT:
41                         dispName = daylight ? sdst : sstd;
42                         break;
43                     }
44                 }
45             }
46
47 //            {
48 //                switch (style) {
49 //                case TimeZone.LONG:
50 //                    dispName = daylight ?
51 //                            tznames.getDisplayName(canonicalID, NameType.LONG_DAYLIGHT, date) :
52 //                            tznames.getDisplayName(canonicalID, NameType.LONG_STANDARD, date);
53 //                    break;
54 //                case TimeZone.SHORT:
55 //                    dispName = daylight ?
56 //                            tznames.getDisplayName(canonicalID, NameType.SHORT_DAYLIGHT, date) :
57 //                            tznames.getDisplayName(canonicalID, NameType.SHORT_STANDARD, date);
58 //                    break;
59 //                }
60 //            }
61         }
62         return dispName;
63     }
64
65     @Override
66     public Locale[] getAvailableLocales() {
67         return ICULocaleServiceProvider.getAvailableLocales();
68     }
69
70 }