Java Code Examples for java.util.TimeZone#LONG

The following examples show how to use java.util.TimeZone#LONG . These examples are extracted from open source projects. 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
@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
@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
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
@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
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
@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
@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 Project: j2objc   File: TimeZoneNames.java    License: 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
@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;
}