DateTimeUtil { public static OffsetDateTime parseOffsetDateTime(final String timestamp) { return OffsetDateTime.parse(timestamp, DateTimeUtil.OFFSET_DATE_TIME); } private  DateTimeUtil(); static OffsetDateTime parseOffsetDateTime(final String timestamp); static final DateTimeFormatter OFFSET_DATE_TIME_EXPANDED; static final DateTimeFormatter OFFSET_DATE_TIME_BASIC; static final DateTimeFormatter OFFSET_DATE_TIME; }
@Test public void parseExpandedFormat() { final OffsetDateTime time = DateTimeUtil.parseOffsetDateTime("1970-01-23T01:23:45-13:37"); assert19700123T012345_1337(time); }
@Test public void parseBasicFormat() { final OffsetDateTime time = DateTimeUtil.parseOffsetDateTime("19700123T012345-1337"); assert19700123T012345_1337(time); }
@Test public void parseShortExpandedFormat() { final OffsetDateTime time = DateTimeUtil.parseOffsetDateTime("1970-01-01T01+13"); assertThat(time.toEpochSecond()).isEqualTo(-12 * 60 * 60); }
@Test public void parseShortBasicFormat() { final OffsetDateTime time = DateTimeUtil.parseOffsetDateTime("1970-01-01T01+13"); assertThat(time.toEpochSecond()).isEqualTo(-12 * 60 * 60); }
@Test public void parseZuluTime() { final OffsetDateTime time = DateTimeUtil.parseOffsetDateTime("19700123T012345Z"); assertThat(time.getOffset().getLong(ChronoField.OFFSET_SECONDS)).isEqualTo(0); }
@Test(expected = DateTimeException.class) public void monthTooBig() { DateTimeUtil.parseOffsetDateTime("1970-13-01T00Z"); }
@Test(expected = DateTimeException.class) public void dayTooBig() { DateTimeUtil.parseOffsetDateTime("1970-12-32T00Z"); }
@Test(expected = DateTimeException.class) public void hourTooBig() { DateTimeUtil.parseOffsetDateTime("1970-12-31T25Z"); }
@Test(expected = DateTimeException.class) public void minuteTooBig() { DateTimeUtil.parseOffsetDateTime("1970-12-31T23:60Z"); }
@Test(expected = DateTimeException.class) public void leapSecondsNotSupported() { final OffsetDateTime time = DateTimeUtil.parseOffsetDateTime("1972-06-30T23:59:60Z"); assertThat(time.toEpochSecond()).isEqualTo(2287785600L); }
@Test(expected = DateTimeException.class) public void secondTooBig() { DateTimeUtil.parseOffsetDateTime("1970-12-31T23:59:60Z"); }
@Test(expected = DateTimeException.class) public void offsetHourTooBig() { DateTimeUtil.parseOffsetDateTime("1970-12-31T23:59:59+19"); }
@Test(expected = DateTimeException.class) public void offsetMinuteTooBig() { DateTimeUtil.parseOffsetDateTime("1970-12-31T23:59:59+01:60"); }
@Test(expected = DateTimeException.class) public void offsetSecondsNotSupported() { final OffsetDateTime time = DateTimeUtil.parseOffsetDateTime("1970-12-31T23:59:59+03:59:59"); assertThat(time.getLong(ChronoField.OFFSET_SECONDS)).isEqualTo(3 * 60 * 60 + 59 * 60 + 59); }
@Test(expected = DateTimeException.class) public void offsetMillisecondsNotSupported() { DateTimeUtil.parseOffsetDateTime("1970-12-31T23:59:59+03:59:59.999"); }
@Test(expected = DateTimeException.class) public void notZuluTime() { DateTimeUtil.parseOffsetDateTime("1970-12-31T23:59:60X"); }