Search in sources :

Example 6 with ResolverStyle

use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.

the class TCKHijrahChronology method data_resolve_styles.

@DataProvider(name = "resolve_styles")
Object[][] data_resolve_styles() {
    Object[][] result = new Object[ResolverStyle.values().length][];
    int i = 0;
    for (ResolverStyle style : ResolverStyle.values()) {
        result[i++] = new Object[] { style };
    }
    return result;
}
Also used : ResolverStyle(java.time.format.ResolverStyle) DataProvider(org.testng.annotations.DataProvider)

Example 7 with ResolverStyle

use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.

the class TCKDateTimeParseResolver method test_resolveFourToTime.

@Test(dataProvider = "resolveFourToTime")
public void test_resolveFourToTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(HOUR_OF_DAY, hour).parseDefaulting(MINUTE_OF_HOUR, min).parseDefaulting(SECOND_OF_MINUTE, sec).parseDefaulting(NANO_OF_SECOND, nano).toFormatter();
    ResolverStyle[] styles = (style != null ? new ResolverStyle[] { style } : ResolverStyle.values());
    for (ResolverStyle s : styles) {
        if (expectedTime != null) {
            TemporalAccessor accessor = f.withResolverStyle(s).parse("");
            assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
            assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
        } else {
            try {
                f.withResolverStyle(style).parse("");
                fail();
            } catch (DateTimeParseException ex) {
            // expected
            }
        }
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) TemporalAccessor(java.time.temporal.TemporalAccessor) ResolverStyle(java.time.format.ResolverStyle) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 8 with ResolverStyle

use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.

the class TCKJapaneseChronology method test_resolve_yearOfEra_eraOnly_invalidTooLarge.

public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() {
    for (ResolverStyle style : ResolverStyle.values()) {
        Map<TemporalField, Long> fieldValues = new HashMap<>();
        fieldValues.put(ChronoField.ERA, JapaneseEra.values()[JapaneseEra.values().length - 1].getValue() + 1L);
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed: " + style);
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) ResolverStyle(java.time.format.ResolverStyle)

Example 9 with ResolverStyle

use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.

the class TCKJapaneseChronology method test_resolve_yearOfEra_eraOnly_invalidTooSmall.

public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() {
    for (ResolverStyle style : ResolverStyle.values()) {
        Map<TemporalField, Long> fieldValues = new HashMap<>();
        fieldValues.put(ChronoField.ERA, JapaneseEra.MEIJI.getValue() - 1L);
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed: " + style);
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) ResolverStyle(java.time.format.ResolverStyle)

Example 10 with ResolverStyle

use of java.time.format.ResolverStyle in project jdk8u_jdk by JetBrains.

the class TCKInstantPrinterParser method test_parse_leapSecond.

@Test
public void test_parse_leapSecond() {
    Instant expected = OffsetDateTime.of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset.UTC).toInstant();
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
    for (ResolverStyle style : ResolverStyle.values()) {
        TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T23:59:60.123456789Z");
        assertEquals(parsed.query(Instant::from), expected);
        assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
        assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.TRUE);
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Instant(java.time.Instant) ResolverStyle(java.time.format.ResolverStyle) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Aggregations

ResolverStyle (java.time.format.ResolverStyle)11 DateTimeFormatter (java.time.format.DateTimeFormatter)5 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)5 TemporalAccessor (java.time.temporal.TemporalAccessor)5 Test (org.testng.annotations.Test)5 DataProvider (org.testng.annotations.DataProvider)4 DateTimeException (java.time.DateTimeException)2 Instant (java.time.Instant)2 DateTimeParseException (java.time.format.DateTimeParseException)2 TemporalField (java.time.temporal.TemporalField)2 HashMap (java.util.HashMap)2 LocalDate (java.time.LocalDate)1 ChronoLocalDate (java.time.chrono.ChronoLocalDate)1 HijrahEra (java.time.chrono.HijrahEra)1 JapaneseEra (java.time.chrono.JapaneseEra)1