Java Code Examples for java.time.zone.ZoneRulesProvider#getAvailableZoneIds()

The following examples show how to use java.time.zone.ZoneRulesProvider#getAvailableZoneIds() . 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 openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
 
Example 2
Source File: DateTimeFormatterBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
 
Example 3
Source File: TCKZoneRulesProvider.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_registerProvider() {
    Set<String> pre = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(pre.contains("FooLocation"), false);
    ZoneRulesProvider.registerProvider(new MockTempProvider());
    assertEquals(pre.contains("FooLocation"), false);
    Set<String> post = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(post.contains("FooLocation"), true);
    assertEquals(ZoneRulesProvider.getRules("FooLocation", false), ZoneOffset.of("+01:45").getRules());
}
 
Example 4
Source File: TestZoneTextPrinterParser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 5
Source File: TestZoneTextPrinterParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 6
Source File: TestZoneTextPrinterParser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = new Random();
    int N = 50;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 7
Source File: TestZoneTextPrinterParser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void test_ParseText() {
    Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    for (Locale locale : locales) {
        parseText(zids, locale, TextStyle.FULL, false);
        parseText(zids, locale, TextStyle.FULL, true);
        parseText(zids, locale, TextStyle.SHORT, false);
        parseText(zids, locale, TextStyle.SHORT, true);
    }
}
 
Example 8
Source File: TestZoneTextPrinterParser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_ParseText() {
    Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    for (Locale locale : locales) {
        parseText(zids, locale, TextStyle.FULL, false);
        parseText(zids, locale, TextStyle.FULL, true);
        parseText(zids, locale, TextStyle.SHORT, false);
        parseText(zids, locale, TextStyle.SHORT, true);
    }
}
 
Example 9
Source File: TCKZoneRulesProvider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 10
Source File: TestZoneTextPrinterParser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_ParseText() {
    Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    for (Locale locale : locales) {
        parseText(zids, locale, TextStyle.FULL, false);
        parseText(zids, locale, TextStyle.FULL, true);
        parseText(zids, locale, TextStyle.SHORT, false);
        parseText(zids, locale, TextStyle.SHORT, true);
    }
}
 
Example 11
Source File: TCKZoneRulesProvider.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 12
Source File: TCKZoneRulesProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_registerProvider() {
    Set<String> pre = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(pre.contains("FooLocation"), false);
    ZoneRulesProvider.registerProvider(new MockTempProvider());
    assertEquals(pre.contains("FooLocation"), false);
    Set<String> post = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(post.contains("FooLocation"), true);
    assertEquals(ZoneRulesProvider.getRules("FooLocation", false), ZoneOffset.of("+01:45").getRules());
}
 
Example 13
Source File: TCKZoneRulesProvider.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getAvailableGroupIds() {
    Set<String> zoneIds = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds.contains("Europe/London"), true);
    zoneIds.clear();
    assertEquals(zoneIds.size(), 0);
    Set<String> zoneIds2 = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(zoneIds2.contains("Europe/London"), true);
}
 
Example 14
Source File: TestZoneTextPrinterParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
Example 15
Source File: TCKZoneRulesProvider.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_registerProvider() {
    Set<String> pre = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(pre.contains("FooLocation"), false);
    ZoneRulesProvider.registerProvider(new MockTempProvider());
    assertEquals(pre.contains("FooLocation"), false);
    Set<String> post = ZoneRulesProvider.getAvailableZoneIds();
    assertEquals(post.contains("FooLocation"), true);
    assertEquals(ZoneRulesProvider.getRules("FooLocation", false), ZoneOffset.of("+01:45").getRules());
}
 
Example 16
Source File: ZoneId.java    From Java8CN with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the set of available zone IDs.
 * <p>
 * This set includes the string form of all available region-based IDs.
 * Offset-based zone IDs are not included in the returned set.
 * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}.
 * <p>
 * The set of zone IDs can increase over time, although in a typical application
 * the set of IDs is fixed. Each call to this method is thread-safe.
 *
 * @return a modifiable copy of the set of zone IDs, not null
 */
public static Set<String> getAvailableZoneIds() {
    return ZoneRulesProvider.getAvailableZoneIds();
}
 
Example 17
Source File: ZoneId.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the set of available zone IDs.
 * <p>
 * This set includes the string form of all available region-based IDs.
 * Offset-based zone IDs are not included in the returned set.
 * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}.
 * <p>
 * The set of zone IDs can increase over time, although in a typical application
 * the set of IDs is fixed. Each call to this method is thread-safe.
 *
 * @return a modifiable copy of the set of zone IDs, not null
 */
public static Set<String> getAvailableZoneIds() {
    return ZoneRulesProvider.getAvailableZoneIds();
}
 
Example 18
Source File: ZoneId.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the set of available zone IDs.
 * <p>
 * This set includes the string form of all available region-based IDs.
 * Offset-based zone IDs are not included in the returned set.
 * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}.
 * <p>
 * The set of zone IDs can increase over time, although in a typical application
 * the set of IDs is fixed. Each call to this method is thread-safe.
 *
 * @return a modifiable copy of the set of zone IDs, not null
 */
public static Set<String> getAvailableZoneIds() {
    return ZoneRulesProvider.getAvailableZoneIds();
}
 
Example 19
Source File: ZoneId.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the set of available zone IDs.
 * <p>
 * This set includes the string form of all available region-based IDs.
 * Offset-based zone IDs are not included in the returned set.
 * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}.
 * <p>
 * The set of zone IDs can increase over time, although in a typical application
 * the set of IDs is fixed. Each call to this method is thread-safe.
 *
 * @return a modifiable copy of the set of zone IDs, not null
 */
public static Set<String> getAvailableZoneIds() {
    return new HashSet<String>(ZoneRulesProvider.getAvailableZoneIds());
}
 
Example 20
Source File: ZoneId.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the set of available zone IDs.
 * <p>
 * This set includes the string form of all available region-based IDs.
 * Offset-based zone IDs are not included in the returned set.
 * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}.
 * <p>
 * The set of zone IDs can increase over time, although in a typical application
 * the set of IDs is fixed. Each call to this method is thread-safe.
 *
 * @return a modifiable copy of the set of zone IDs, not null
 */
public static Set<String> getAvailableZoneIds() {
    return ZoneRulesProvider.getAvailableZoneIds();
}