Search in sources :

Example 1 with ResolverStyle

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

the class TCKDateTimeParseResolver method test_resolveFourToDateTime.

@Test(dataProvider = "resolveFourToTime")
public void test_resolveFourToDateTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(YEAR, 2012).parseDefaulting(MONTH_OF_YEAR, 6).parseDefaulting(DAY_OF_MONTH, 30).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());
    if (expectedTime != null && excessPeriod != null) {
        LocalDate expectedDate = LocalDate.of(2012, 6, 30).plus(excessPeriod);
        for (ResolverStyle s : styles) {
            TemporalAccessor accessor = f.withResolverStyle(s).parse("");
            assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate, "ResolverStyle: " + s);
            assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO, "ResolverStyle: " + s);
        }
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ResolverStyle(java.time.format.ResolverStyle) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) ChronoLocalDate(java.time.chrono.ChronoLocalDate) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 2 with ResolverStyle

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

the class TCKInstantPrinterParser method test_parse_endOfDay.

@Test
public void test_parse_endOfDay() {
    Instant expected = OffsetDateTime.of(1970, 2, 4, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
    for (ResolverStyle style : ResolverStyle.values()) {
        TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T24:00:00Z");
        assertEquals(parsed.query(Instant::from), expected);
        assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
        assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.FALSE);
    }
}
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)

Example 3 with ResolverStyle

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

the class TCKHijrahChronology method data_resolve_styleByEra.

//-----------------------------------------------------------------------
// Tests for HijrahChronology resolve
//-----------------------------------------------------------------------
@DataProvider(name = "resolve_styleByEra")
Object[][] data_resolve_styleByEra() {
    Object[][] result = new Object[ResolverStyle.values().length * HijrahEra.values().length][];
    int i = 0;
    for (ResolverStyle style : ResolverStyle.values()) {
        for (HijrahEra era : HijrahEra.values()) {
            result[i++] = new Object[] { style, era };
        }
    }
    return result;
}
Also used : ResolverStyle(java.time.format.ResolverStyle) HijrahEra(java.time.chrono.HijrahEra) DataProvider(org.testng.annotations.DataProvider)

Example 4 with ResolverStyle

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

the class TCKJapaneseChronology 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 5 with ResolverStyle

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

the class TCKJapaneseChronology method data_resolve_styleByEra.

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
@DataProvider(name = "resolve_styleByEra")
Object[][] data_resolve_styleByEra() {
    Object[][] result = new Object[ResolverStyle.values().length * JapaneseEra.values().length][];
    int i = 0;
    for (ResolverStyle style : ResolverStyle.values()) {
        for (JapaneseEra era : JapaneseEra.values()) {
            result[i++] = new Object[] { style, era };
        }
    }
    return result;
}
Also used : ResolverStyle(java.time.format.ResolverStyle) JapaneseEra(java.time.chrono.JapaneseEra) DataProvider(org.testng.annotations.DataProvider)

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