2 *******************************************************************************
\r
3 * Copyright (C) 2008, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.impl.javaspi.util;
\r
9 import java.util.Locale;
\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
15 public class TimeZoneNameProviderICU extends java.util.spi.TimeZoneNameProvider {
\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
25 // This is ugly hack, but no simple solution to check if
\r
26 // the localized name was picked up.
\r
28 for (int i = 0; i < disp.length(); i++) {
\r
29 char c = disp.charAt(i);
\r
30 if (UCharacter.isDigit(c)) {
\r
34 // If there are more than 3 numbers, this code assume GMT format was used.
\r
35 if (numDigits >= 3) {
\r
40 // ICU uses standard name for daylight name when the zone does not use
\r
41 // daylight saving time.
\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
53 public Locale[] getAvailableLocales() {
\r
54 return ICULocaleServiceProvider.getAvailableLocales();
\r