Java Code Examples for java.util.TimeZone#LONG

The following examples show how to use java.util.TimeZone#LONG . 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: DateTimeFormatterBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean print(DateTimePrintContext context, StringBuilder buf) {
    ZoneId zone = context.getValue(TemporalQueries.zoneId());
    if (zone == null) {
        return false;
    }
    if (zone.normalized() instanceof ZoneOffset) {
        buf.append(zone.getId());
        return true;
    }
    TemporalAccessor temporal = context.getTemporal();
    boolean daylight = false;
    if (temporal.isSupported(INSTANT_SECONDS)) {
        Instant instant = Instant.ofEpochSecond(temporal.getLong(INSTANT_SECONDS));
        daylight = zone.getRules().isDaylightSavings(instant);
    }
    TimeZone tz = TimeZone.getTimeZone(zone.getId());
    int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
    String text = tz.getDisplayName(daylight, tzstyle, context.getLocale());
    buf.append(text);
    return true;
}
 
Example 2
Source File: TimeZoneNameProviderImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getGenericDisplayName(String id, int style, Locale locale) {
    String[] names = getDisplayNameArray(id, 7, locale);
    if (names != null && names.length >= 7) {
        return names[(style == TimeZone.LONG) ? 5 : 6];
    }
    return null;
}
 
Example 3
Source File: TimeZoneNamesTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static boolean testPropertyEntry( Locale locale, String entry, String value ) {
    boolean result = true;
    String[] params = entry.split("\\.");
    if (params.length != 3) {
        System.out.println("Incorrect property file entry="+entry+" "+params.length);
        result = false;
    } else {
        boolean isDaylight = true;
        int nameType = TimeZone.LONG;

        if (params[2].equals("short"))
            nameType = TimeZone.SHORT;

        if (params[1].equals("standard"))
            isDaylight = false;

        // Names with non-requested tz name type are ignored
        if (requestedTestType.equals(params[2])) {
            try {
                if (params[1].equals("generic"))
                    testGenericTZName( locale, params[0], nameType, value );
                else
                    testTZName( locale, params[0], isDaylight, nameType, value );
            } catch (RuntimeException e) {
                System.out.println( "Test FAILED: "+e );
                result = false;
            }
        }
    }
    return result;
}
 
Example 4
Source File: TimeZoneNameProviderImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getGenericDisplayName(String id, int style, Locale locale) {
    String[] names = getDisplayNameArray(id, 7, locale);
    if (names != null && names.length >= 7) {
        return names[(style == TimeZone.LONG) ? 5 : 6];
    }
    return null;
}
 
Example 5
Source File: TimeZoneNamesTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean testPropertyEntry( Locale locale, String entry, String value ) {
    boolean result = true;
    String[] params = entry.split("\\.");
    if (params.length != 3) {
        System.out.println("Incorrect property file entry="+entry+" "+params.length);
        result = false;
    } else {
        boolean isDaylight = true;
        int nameType = TimeZone.LONG;

        if (params[2].equals("short"))
            nameType = TimeZone.SHORT;

        if (params[1].equals("standard"))
            isDaylight = false;

        // Names with non-requested tz name type are ignored
        if (requestedTestType.equals(params[2])) {
            try {
                if (params[1].equals("generic"))
                    testGenericTZName( locale, params[0], nameType, value );
                else
                    testTZName( locale, params[0], isDaylight, nameType, value );
            } catch (RuntimeException e) {
                System.out.println( "Test FAILED: "+e );
                result = false;
            }
        }
    }
    return result;
}
 
Example 6
Source File: TimeZoneNameProviderImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getGenericDisplayName(String id, int style, Locale locale) {
    String[] names = getDisplayNameArray(id, 7, locale);
    if (names != null && names.length >= 7) {
        return names[(style == TimeZone.LONG) ? 5 : 6];
    }
    return null;
}
 
Example 7
Source File: TimeZoneNameProviderImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getGenericDisplayName(String id, int style, Locale locale) {
    String[] names = getDisplayNameArray(id, 7, locale);
    if (names != null && names.length >= 7) {
        return names[(style == TimeZone.LONG) ? 5 : 6];
    }
    return null;
}
 
Example 8
Source File: TimeZoneNames.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate string from 'zoneStrings'. Used with getZoneStrings.
 */
public static String getDisplayName(String[][] zoneStrings, String id, boolean daylight, int style) {
    String[] needle = new String[] { id };
    int index = Arrays.binarySearch(zoneStrings, needle, ZONE_STRINGS_COMPARATOR);
    if (index >= 0) {
        String[] row = zoneStrings[index];
        if (daylight) {
            return (style == TimeZone.LONG) ? row[LONG_NAME_DST] : row[SHORT_NAME_DST];
        } else {
            return (style == TimeZone.LONG) ? row[LONG_NAME] : row[SHORT_NAME];
        }
    }
    return null;
}
 
Example 9
Source File: DateTimeFormatterBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
    // this is a poor implementation that handles some but not all of the spec
    // JDK8 has a lot of extra information here
    Map<String, String> ids = new TreeMap<String, String>(LENGTH_COMPARATOR);
    for (String id : ZoneId.getAvailableZoneIds()) {
        ids.put(id, id);
        TimeZone tz = TimeZone.getTimeZone(id);
        int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
        String textWinter = tz.getDisplayName(false, tzstyle, context.getLocale());
        if (id.startsWith("Etc/") || (!textWinter.startsWith("GMT+") && !textWinter.startsWith("GMT+"))) {
            ids.put(textWinter, id);
        }
        String textSummer = tz.getDisplayName(true, tzstyle, context.getLocale());
        if (id.startsWith("Etc/") || (!textSummer.startsWith("GMT+") && !textSummer.startsWith("GMT+"))) {
            ids.put(textSummer, id);
        }
    }
    for (Entry<String, String> entry : ids.entrySet()) {
        String name = entry.getKey();
        if (context.subSequenceEquals(text, position, name, 0, name.length())) {
            context.setParsed(ZoneId.of(entry.getValue()));
            return position + name.length();
        }
    }
    return ~position;
}