]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/localespi/src/com/ibm/icu/impl/javaspi/util/TimeZoneNameProviderICU.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / localespi / src / com / ibm / icu / impl / javaspi / util / TimeZoneNameProviderICU.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 2008, International Business Machines Corporation and         *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 package com.ibm.icu.impl.javaspi.util;\r
8 \r
9 import java.util.Locale;\r
10 \r
11 import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;\r
12 import com.ibm.icu.lang.UCharacter;\r
13 import com.ibm.icu.util.TimeZone;\r
14 \r
15 public class TimeZoneNameProviderICU extends java.util.spi.TimeZoneNameProvider {\r
16 \r
17     @Override\r
18     public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {\r
19         TimeZone tz = TimeZone.getTimeZone(ID);\r
20         Locale actualLocale = ICULocaleServiceProvider.canonicalize(locale);\r
21         String disp = tz.getDisplayName(daylight, style, actualLocale);\r
22         if (disp.length() == 0) {\r
23             return null;\r
24         }\r
25         // This is ugly hack, but no simple solution to check if\r
26         // the localized name was picked up.\r
27         int numDigits = 0;\r
28         for (int i = 0; i < disp.length(); i++) {\r
29             char c = disp.charAt(i);\r
30             if (UCharacter.isDigit(c)) {\r
31                 numDigits++;\r
32             }\r
33         }\r
34         // If there are more than 3 numbers, this code assume GMT format was used.\r
35         if (numDigits >= 3) {\r
36             return null;\r
37         }\r
38 \r
39         if (daylight) {\r
40             // ICU uses standard name for daylight name when the zone does not use\r
41             // daylight saving time.\r
42 \r
43             // This is yet another ugly hack to support the JDK's behavior\r
44             String stdDisp = tz.getDisplayName(false, style, actualLocale);\r
45             if (disp.equals(stdDisp)) {\r
46                 return null;\r
47             }\r
48         }\r
49         return disp;\r
50     }\r
51 \r
52     @Override\r
53     public Locale[] getAvailableLocales() {\r
54         return ICULocaleServiceProvider.getAvailableLocales();\r
55     }\r
56 \r
57 }\r