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

The following examples show how to use java.time.zone.ZoneRulesProvider#getRules() . 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: TCKZoneRulesProvider.java    From openjdk-jdk9 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 2
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 3
Source File: TCKZoneRulesProvider.java    From openjdk-jdk8u 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 4
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_getRules_StringBoolean() {
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertNotNull(rules);
    ZoneRules rules2 = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(rules2, rules);
}
 
Example 5
Source File: TCKZoneRulesProvider.java    From jdk8u_jdk 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 6
Source File: TCKZoneRulesProvider.java    From openjdk-jdk8u 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 7
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 8
Source File: TCKZoneRulesProvider.java    From jdk8u60 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 9
Source File: ZoneRegion.java    From hottub 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 10
Source File: ZoneRegion.java    From jdk8u-jdk 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 11
Source File: ZoneRegion.java    From openjdk-jdk9 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 12
Source File: ZoneRegion.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
@Override
public ZoneRules getRules() {
    // additional query for group provider when null allows for possibility
    // that the provider was updated after the ZoneId was created
    return (rules != null ? rules : ZoneRulesProvider.getRules(id, false));
}
 
Example 13
Source File: TCKZoneRulesProvider.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_getRules_StringBoolean_null() {
    ZoneRulesProvider.getRules(null, false);
}
 
Example 14
Source File: TCKZoneRulesProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_getRules_StringBoolean_null() {
    ZoneRulesProvider.getRules(null, false);
}
 
Example 15
Source File: TCKZoneRulesProvider.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ZoneRulesException.class)
public void test_getRules_StringBoolean_unknownId() {
    ZoneRulesProvider.getRules("Europe/Lon", false);
}
 
Example 16
Source File: ZoneRegion.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ZoneRules getRules() {
    // additional query for group provider when null allows for possibility
    // that the provider was updated after the ZoneId was created
    return (rules != null ? rules : ZoneRulesProvider.getRules(id, false));
}
 
Example 17
Source File: ZoneRegion.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ZoneRules getRules() {
    // additional query for group provider when null allows for possibility
    // that the provider was updated after the ZoneId was created
    return (rules != null ? rules : ZoneRulesProvider.getRules(id, false));
}
 
Example 18
Source File: TCKZoneRulesProvider.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ZoneRulesException.class)
public void test_getRules_StringBoolean_unknownId() {
    ZoneRulesProvider.getRules("Europe/Lon", false);
}
 
Example 19
Source File: TCKZoneRulesProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ZoneRulesException.class)
public void test_getRules_StringBoolean_unknownId() {
    ZoneRulesProvider.getRules("Europe/Lon", false);
}
 
Example 20
Source File: TCKZoneRulesProvider.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ZoneRulesException.class)
public void test_getRules_StringBoolean_unknownId() {
    ZoneRulesProvider.getRules("Europe/Lon", false);
}