Search in sources :

Example 1 with DateTimeParseException

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;
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) ZonedDateTime(java.time.ZonedDateTime) DateTimeParseException(java.time.format.DateTimeParseException)

Example 2 with DateTimeParseException

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
        }
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 3 with DateTimeParseException

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
        }
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 4 with DateTimeParseException

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;
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 5 with DateTimeParseException

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());
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) Duration(java.time.Duration) Test(org.testng.annotations.Test)

Aggregations

DateTimeParseException (java.time.format.DateTimeParseException)29 DateTimeFormatter (java.time.format.DateTimeFormatter)15 Test (org.testng.annotations.Test)14 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)10 TemporalAccessor (java.time.temporal.TemporalAccessor)10 LocalDate (java.time.LocalDate)6 Instant (java.time.Instant)5 LocalDateTime (java.time.LocalDateTime)5 Duration (java.time.Duration)2 ResolverStyle (java.time.format.ResolverStyle)2 Matcher (java.util.regex.Matcher)2 Cache (com.github.benmanes.caffeine.cache.Cache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 Conference (com.github.lantoine.lamsadetools.conferences.Conference)1 AddressInfos (com.github.lantoine.lamsadetools.map.AddressInfos)1 GoogleItineraryMap (com.github.lantoine.lamsadetools.map.GoogleItineraryMap)1 UserDetails (com.github.lantoine.lamsadetools.setCoordinates.UserDetails)1 KvDouble (com.torodb.kvdocument.values.KvDouble)1 KvLong (com.torodb.kvdocument.values.KvLong)1 InstantKvInstant (com.torodb.kvdocument.values.heap.InstantKvInstant)1