use of java.time.format.DateTimeParseException in project GCViewer by chewiebug.
the class AbstractDataReaderSun method parseDatestamp.
/**
* Parses a datestamp in <code>line</code> at <code>pos</code>.
*
* @param line current line.
* @param pos current parse position.
* @return returns parsed datestamp if found one, <code>null</code> otherwise.
* @throws ParseException if line could not be parsed.
*/
protected ZonedDateTime parseDatestamp(String line, ParseInformation pos) throws ParseException {
ZonedDateTime zonedDateTime = null;
if (nextIsDatestamp(line, pos)) {
try {
zonedDateTime = ZonedDateTime.parse(line.substring(pos.getIndex(), pos.getIndex() + LENGTH_OF_DATESTAMP - 1), DATE_TIME_FORMATTER);
pos.setIndex(pos.getIndex() + LENGTH_OF_DATESTAMP);
if (pos.getFirstDateStamp() == null) {
pos.setFirstDateStamp(zonedDateTime);
}
} catch (DateTimeParseException e) {
throw new ParseException(e.toString(), line);
}
}
return zonedDateTime;
}
use of java.time.format.DateTimeParseException in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveClockHourOfDay.
@Test(dataProvider = "resolveClockHourOfDay")
public void test_resolveClockHourOfDay(ResolverStyle style, long value, Integer expectedHour, int expectedDays) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_DAY).toFormatter();
if (expectedHour != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(expectedHour, 0));
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
} else {
try {
f.withResolverStyle(style).parse(str);
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
use of java.time.format.DateTimeParseException in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveSecondOfDay.
@Test(dataProvider = "resolveSecondOfDay")
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();
if (expectedSecond != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
} else {
try {
f.withResolverStyle(style).parse(str);
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
use of java.time.format.DateTimeParseException in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatters method test_parse_basicIsoDate_largeYear.
@Test(expectedExceptions = DateTimeParseException.class)
public void test_parse_basicIsoDate_largeYear() {
try {
LocalDate expected = LocalDate.of(123456, 6, 3);
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.parse("+1234560603", LocalDate::from), expected);
} catch (DateTimeParseException ex) {
assertEquals(ex.getErrorIndex(), 0);
assertEquals(ex.getParsedString(), "+1234560603");
throw ex;
}
}
use of java.time.format.DateTimeParseException in project jdk8u_jdk by JetBrains.
the class TCKDuration method factory_parse_minus.
@Test(dataProvider = "parseSuccess")
public void factory_parse_minus(String text, long expectedSeconds, int expectedNanoOfSecond) {
Duration test;
try {
test = Duration.parse("-" + text);
} catch (DateTimeParseException ex) {
assertEquals(expectedSeconds == Long.MIN_VALUE, true);
return;
}
// not inside try/catch or it breaks test
assertEquals(test, Duration.ofSeconds(expectedSeconds, expectedNanoOfSecond).negated());
}
Aggregations