Java Code Examples for sun.util.calendar.ZoneInfoFile#toCustomID()

The following examples show how to use sun.util.calendar.ZoneInfoFile#toCustomID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeZoneNameProviderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private String[] getDisplayNameArray(String id, Locale locale) {
    Objects.requireNonNull(id);
    Objects.requireNonNull(locale);

    String[] ret =
        LocaleProviderAdapter.forType(type).getLocaleResources(locale).getTimeZoneNames(id);

    if (Objects.nonNull(ret) && type == LocaleProviderAdapter.Type.CLDR) {
        // check for CLDR's "no inheritance marker"
        for (int index = 0; index < ret.length; index++) {
            TimeZone tz = null;
            if (CLDR_NO_INHERITANCE_MARKER.equals(ret[index])) {
                if (Objects.isNull(tz)) {
                    tz = TimeZone.getTimeZone(id);
                }
                int offset = tz.getRawOffset();
                if (index == 3 || index == 4) { // daylight
                    offset += tz.getDSTSavings();
                }
                ret[index] = ZoneInfoFile.toCustomID(offset);
            }
        }
    }

    return ret;
}
 
Example 2
Source File: TimeZone.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 3
Source File: TimeZone.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 4
Source File: TimeZone.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 5
Source File: TimeZone.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 6
Source File: TimeZone.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 7
Source File: TimeZone.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 8
Source File: TimeZone.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 9
Source File: TimeZone.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 10
Source File: TimeZone.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 11
Source File: TimeZone.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 12
Source File: TimeZone.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * {@code Locale} search path of {@code ResourceBundle}} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * {@code Locale}} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @throws    IllegalArgumentException if {@code style} is invalid.
 * @throws    NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 13
Source File: TimeZone.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 14
Source File: TimeZone.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 15
Source File: TimeZone.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 16
Source File: TimeZone.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 17
Source File: TimeZone.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 18
Source File: TimeZone.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }
    String id = getID();
    String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
    if (name != null) {
        return name;
    }

    if (id.startsWith("GMT") && id.length() > 3) {
        char sign = id.charAt(3);
        if (sign == '+' || sign == '-') {
            return id;
        }
    }
    int offset = getRawOffset();
    if (daylight) {
        offset += getDSTSavings();
    }
    return ZoneInfoFile.toCustomID(offset);
}
 
Example 19
Source File: TimeZone.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a name in the specified {@code style} of this {@code TimeZone}
 * suitable for presentation to the user in the specified {@code
 * locale}. If the specified {@code daylight} is {@code true}, a Daylight
 * Saving Time name is returned (even if this {@code TimeZone} doesn't
 * observe Daylight Saving Time). Otherwise, a Standard Time name is
 * returned.
 *
 * <p>When looking up a time zone name, the {@linkplain
 * ResourceBundle.Control#getCandidateLocales(String,Locale) default
 * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
 * from the specified {@code locale} is used. (No {@linkplain
 * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
 * <code>Locale</code>} search is performed.) If a time zone name in any
 * {@code Locale} of the search path, including {@link Locale#ROOT}, is
 * found, the name is returned. Otherwise, a string in the
 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
 *
 * @param daylight {@code true} specifying a Daylight Saving Time name, or
 *                 {@code false} specifying a Standard Time name
 * @param style either {@link #LONG} or {@link #SHORT}
 * @param locale   the locale in which to supply the display name.
 * @return the human-readable name of this time zone in the given locale.
 * @exception IllegalArgumentException if {@code style} is invalid.
 * @exception NullPointerException if {@code locale} is {@code null}.
 * @since 1.2
 * @see java.text.DateFormatSymbols#getZoneStrings()
 */
public String getDisplayName(boolean daylight, int style, Locale locale) {
    if (style != SHORT && style != LONG) {
        throw new IllegalArgumentException("Illegal style: " + style);
    }

    String id = getID();
    String[] names = getDisplayNames(id, locale);
    if (names == null) {
        if (id.startsWith("GMT")) {
            char sign = id.charAt(3);
            if (sign == '+' || sign == '-') {
                return id;
            }
        }
        int offset = getRawOffset();
        if (daylight) {
            offset += getDSTSavings();
        }
        return ZoneInfoFile.toCustomID(offset);
    }

    int index = daylight ? 3 : 1;
    if (style == SHORT) {
        index++;
    }
    return names[index];
}