Java Code Examples for org.threeten.bp.ZoneId#of()

The following examples show how to use org.threeten.bp.ZoneId#of() . 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: TestDateTimeFormatters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test(dataProvider="sample_isoDateTime")
public void test_parse_isoDateTime(
        Integer year, Integer month, Integer day,
        Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
        String input, Class<?> invalid) {
    if (input != null) {
        Expected expected = createDateTime(year, month, day, hour, min, sec, nano);
        if (offsetId != null) {
            expected.fieldValues.put(OFFSET_SECONDS, (long) ZoneOffset.of(offsetId).getTotalSeconds());
            if (zoneId != null) {
                expected.zone = ZoneId.of(zoneId);
            }
        }
        assertParseMatch(DateTimeFormatter.ISO_DATE_TIME.parseUnresolved(input, new ParsePosition(0)), expected);
    }
}
 
Example 2
Source File: DateTimeFormatterBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ZoneId convertToZone(Set<String> regionIds, String parsedZoneId, boolean caseSensitive) {
    if (parsedZoneId == null) {
        return null;
    }
    if (caseSensitive) {
        return (regionIds.contains(parsedZoneId) ? ZoneId.of(parsedZoneId) : null);
    } else {
        for (String regionId : regionIds) {
            if (regionId.equalsIgnoreCase(parsedZoneId)) {
                return ZoneId.of(regionId);
            }
        }
        return null;
    }
}
 
Example 3
Source File: TestMonthDay.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    MonthDay expected = MonthDay.now(Clock.system(zone));
    MonthDay test = MonthDay.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = MonthDay.now(Clock.system(zone));
        test = MonthDay.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 4
Source File: TestYear.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    Year expected = Year.now(Clock.system(zone));
    Year test = Year.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = Year.now(Clock.system(zone));
        test = Year.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 5
Source File: TestYearMonth.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    YearMonth expected = YearMonth.now(Clock.system(zone));
    YearMonth test = YearMonth.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = YearMonth.now(Clock.system(zone));
        test = YearMonth.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 6
Source File: TestZoneIdParser.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@DataProvider(name="zones")
Object[][] populateTestData() {
    Set<String> ids = ZoneRulesProvider.getAvailableZoneIds();
    Object[][] rtnval = new Object[ids.size()][];
    int i = 0;
    for (String id : ids) {
        rtnval[i++] = new Object[] { id, ZoneId.of(id) };
    }
    return rtnval;
}
 
Example 7
Source File: TestDateTimeFormatter.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void test_parse_allZones() throws Exception {
    for (String zoneStr : ZoneId.getAvailableZoneIds()) {
        ZoneId zone = ZoneId.of(zoneStr);
        ZonedDateTime base = ZonedDateTime.of(2014, 12, 31, 12, 0, 0, 0, zone);
        ZonedDateTime test = ZonedDateTime.parse(base.toString());
        assertEquals(test, base);
    }
}
 
Example 8
Source File: TestDateTimeFormatters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void buildCalendrical(Expected expected, String offsetId, String zoneId) {
    if (offsetId != null) {
        expected.add(ZoneOffset.of(offsetId));
    }
    if (zoneId != null) {
        expected.zone = ZoneId.of(zoneId);
    }
}
 
Example 9
Source File: TestDateTimeFormatters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void setZone(String zoneId) {
    if (zoneId != null) {
        this.zoneId = ZoneId.of(zoneId);
    }
}