java.time.zone.ZoneRulesProvider Java Examples

The following examples show how to use java.time.zone.ZoneRulesProvider. 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 jdk8u_jdk 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: DateTimeFormatterBuilder.java    From desugar_jdk_libs 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 #4
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 #5
Source File: DateTimeFormatterBuilder.java    From openjdk-8 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 #6
Source File: DateTimeFormatterBuilder.java    From jdk8u60 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 #7
Source File: DateTimeFormatterBuilder.java    From TencentKona-8 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 #8
Source File: DateTimeFormatterBuilder.java    From jdk8u-jdk 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 #9
Source File: DateTimeFormatterBuilder.java    From dragonwell8_jdk 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 #10
Source File: TCKZoneRulesProvider.java    From openjdk-jdk8u 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 #11
Source File: TCKZoneRulesProvider.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getRules_StringBoolean() {
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertNotNull(rules);
    ZoneRules rules2 = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(rules2, rules);
}
 
Example #12
Source File: TCKZoneRulesProvider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getRules_StringBoolean_dynamic() {
    MockDynamicProvider dynamicProvider = new MockDynamicProvider();
    ZoneRulesProvider.registerProvider(dynamicProvider);

    assertEquals(dynamicProvider.count, 0);
    ZoneRules rules1 = ZoneId.of("DynamicLocation").getRules();
    assertEquals(dynamicProvider.count, 2);
    assertEquals(rules1, dynamicProvider.BASE);
    ZoneRules rules2 = ZoneId.of("DynamicLocation").getRules();
    assertEquals(dynamicProvider.count, 4);
    assertEquals(rules2, dynamicProvider.ALTERNATE);
}
 
Example #13
Source File: TCKZoneRulesProvider.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getRules_StringBoolean() {
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertNotNull(rules);
    ZoneRules rules2 = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(rules2, rules);
}
 
Example #14
Source File: TCKZoneRulesProvider.java    From openjdk-jdk8u 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 #15
Source File: TCKZoneRulesProvider.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getRules_StringBoolean() {
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertNotNull(rules);
    ZoneRules rules2 = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(rules2, rules);
}
 
Example #16
Source File: TCKZoneRulesProvider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example #17
Source File: TestZoneTextPrinterParser.java    From jdk8u60 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 #18
Source File: TestZoneTextPrinterParser.java    From openjdk-jdk8u 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 #19
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 #20
Source File: ZoneRegion.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains an instance of {@code ZoneId} from an identifier.
 *
 * @param zoneId  the time-zone ID, not null
 * @param checkAvailable  whether to check if the zone ID is available
 * @return the zone ID, not null
 * @throws DateTimeException if the ID format is invalid
 * @throws ZoneRulesException if checking availability and the ID cannot be found
 */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
    Objects.requireNonNull(zoneId, "zoneId");
    checkName(zoneId);
    ZoneRules rules = null;
    try {
        // always attempt load for better behavior after deserialization
        rules = ZoneRulesProvider.getRules(zoneId, true);
    } catch (ZoneRulesException ex) {
        if (checkAvailable) {
            throw ex;
        }
    }
    return new ZoneRegion(zoneId, rules);
}
 
Example #21
Source File: TCKZoneRulesProvider.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getRules_StringBoolean_dynamic() {
    MockDynamicProvider dynamicProvider = new MockDynamicProvider();
    ZoneRulesProvider.registerProvider(dynamicProvider);

    assertEquals(dynamicProvider.count, 0);
    ZoneRules rules1 = ZoneId.of("DynamicLocation").getRules();
    assertEquals(dynamicProvider.count, 2);
    assertEquals(rules1, dynamicProvider.BASE);
    ZoneRules rules2 = ZoneId.of("DynamicLocation").getRules();
    assertEquals(dynamicProvider.count, 4);
    assertEquals(rules2, dynamicProvider.ALTERNATE);
}
 
Example #22
Source File: ZoneRegion.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains an instance of {@code ZoneId} from an identifier.
 *
 * @param zoneId  the time-zone ID, not null
 * @param checkAvailable  whether to check if the zone ID is available
 * @return the zone ID, not null
 * @throws DateTimeException if the ID format is invalid
 * @throws ZoneRulesException if checking availability and the ID cannot be found
 */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
    Objects.requireNonNull(zoneId, "zoneId");
    checkName(zoneId);
    ZoneRules rules = null;
    try {
        // always attempt load for better behavior after deserialization
        rules = ZoneRulesProvider.getRules(zoneId, true);
    } catch (ZoneRulesException ex) {
        if (checkAvailable) {
            throw ex;
        }
    }
    return new ZoneRegion(zoneId, rules);
}
 
Example #23
Source File: ZoneRegion.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains an instance of {@code ZoneId} from an identifier.
 *
 * @param zoneId  the time-zone ID, not null
 * @param checkAvailable  whether to check if the zone ID is available
 * @return the zone ID, not null
 * @throws DateTimeException if the ID format is invalid
 * @throws ZoneRulesException if checking availability and the ID cannot be found
 */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
    Objects.requireNonNull(zoneId, "zoneId");
    checkName(zoneId);
    ZoneRules rules = null;
    try {
        // always attempt load for better behavior after deserialization
        rules = ZoneRulesProvider.getRules(zoneId, true);
    } catch (ZoneRulesException ex) {
        if (checkAvailable) {
            throw ex;
        }
    }
    return new ZoneRegion(zoneId, rules);
}
 
Example #24
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_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example #25
Source File: TCKZoneRulesProvider.java    From openjdk-jdk8u-backup 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 #26
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 #27
Source File: TCKZoneRulesProvider.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example #28
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 #29
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_getRules_StringBoolean_dynamic() {
    MockDynamicProvider dynamicProvider = new MockDynamicProvider();
    ZoneRulesProvider.registerProvider(dynamicProvider);

    assertEquals(dynamicProvider.count, 0);
    ZoneRules rules1 = ZoneId.of("DynamicLocation").getRules();
    assertEquals(dynamicProvider.count, 2);
    assertEquals(rules1, dynamicProvider.BASE);
    ZoneRules rules2 = ZoneId.of("DynamicLocation").getRules();
    assertEquals(dynamicProvider.count, 4);
    assertEquals(rules2, dynamicProvider.ALTERNATE);
}
 
Example #30
Source File: TCKZoneRulesProvider.java    From jdk8u60 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());
}