java.util.TimeZone#LONG源码实例Demo

下面列出了java.util.TimeZone#LONG 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: threetenbp   文件: DateTimeFormatterBuilder.java
@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;
}
 
@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;
}
 
源代码3 项目: openjdk-8-source   文件: TimeZoneNamesTest.java
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;
}
 
源代码4 项目: openjdk-8   文件: TimeZoneNameProviderImpl.java
@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;
}
 
源代码5 项目: openjdk-8   文件: TimeZoneNamesTest.java
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;
}
 
源代码6 项目: jdk8u-jdk   文件: TimeZoneNameProviderImpl.java
@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;
}
 
源代码7 项目: jdk8u-dev-jdk   文件: TimeZoneNameProviderImpl.java
@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;
}
 
源代码8 项目: j2objc   文件: TimeZoneNames.java
/**
 * 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;
}
 
源代码9 项目: threetenbp   文件: DateTimeFormatterBuilder.java
@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;
}