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

The following examples show how to use org.threeten.bp.ZonedDateTime#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: TestDateTimeParsing.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@DataProvider(name = "instantZones")
Object[][] data_instantZones() {
    return new Object[][] {
        {LOCALFIELDS_ZONEID, "2014-06-30 01:02:03 Europe/Paris", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS)},
        {LOCALFIELDS_ZONEID, "2014-06-30 01:02:03 +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
        {LOCALFIELDS_OFFSETID, "2014-06-30 01:02:03 +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
        {LOCALFIELDS_WITH_PARIS, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS)},
        {LOCALFIELDS_WITH_0230, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
        {INSTANT_WITH_PARIS, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(PARIS)},
        {INSTANT_WITH_0230, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
        {INSTANT_OFFSETID, "2014-06-30T01:02:03Z +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
        {INSTANT_OFFSETSECONDS, "2014-06-30T01:02:03Z 9000", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
        {INSTANTSECONDS_WITH_PARIS, "86402", Instant.ofEpochSecond(86402).atZone(PARIS)},
        {INSTANTSECONDS_NOS_WITH_PARIS, "86402.123456789", Instant.ofEpochSecond(86402, 123456789).atZone(PARIS)},
        {INSTANTSECONDS_OFFSETSECONDS, "86402 9000", Instant.ofEpochSecond(86402).atZone(OFFSET_0230)},
        {INSTANT_OFFSETSECONDS_ZONE, "2016-10-30T00:30:00Z 7200 Europe/Paris",
            ZonedDateTime.ofStrict(LocalDateTime.of(2016, 10, 30, 2, 30), ZoneOffset.ofHours(2), PARIS)},
        {INSTANT_OFFSETSECONDS_ZONE, "2016-10-30T01:30:00Z 3600 Europe/Paris",
            ZonedDateTime.ofStrict(LocalDateTime.of(2016, 10, 30, 2, 30), ZoneOffset.ofHours(1), PARIS)},
    };
}
 
Example 2
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 3
Source File: TestDateTimeFormatters.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@DataProvider(name="weekDate")
Iterator<Object[]> weekDate() {
    return new Iterator<Object[]>() {
        private ZonedDateTime date = ZonedDateTime.of(LocalDateTime.of(2003, 12, 29, 11, 5, 30), ZoneId.of("Europe/Paris"));
        private ZonedDateTime endDate = date.withYear(2005).withMonth(1).withDayOfMonth(2);
        private int week = 1;
        private int day = 1;

        public boolean hasNext() {
            return !date.isAfter(endDate);
        }
        public Object[] next() {
            StringBuilder sb = new StringBuilder("2004-W");
            if (week < 10) {
                sb.append('0');
            }
            sb.append(week).append('-').append(day).append(date.getOffset());
            Object[] ret = new Object[] {date, sb.toString()};
            date = date.plusDays(1);
            day += 1;
            if (day == 8) {
                day = 1;
                week++;
            }
            return ret;
        }
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}