Search in sources :

Example 21 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TCKDateTimeParseResolver method test_resolveTwoNoChange.

@Test(dataProvider = "resolveTwoNoChange")
public void test_resolveTwoNoChange(TemporalField field1, long value1, TemporalField field2, long value2) {
    String str = value1 + " " + value2;
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).appendLiteral(' ').appendValue(field2).toFormatter();
    TemporalAccessor accessor = f.parse(str);
    assertEquals(accessor.query(TemporalQueries.localDate()), null);
    assertEquals(accessor.query(TemporalQueries.localTime()), null);
    assertEquals(accessor.isSupported(field1), true);
    assertEquals(accessor.isSupported(field2), true);
    assertEquals(accessor.getLong(field1), value1);
    assertEquals(accessor.getLong(field2), value2);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 22 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TCKDateTimeParseResolver method test_fieldResolvesToChronoZonedDateTime_overrideChrono_matches.

@Test
public void test_fieldResolvesToChronoZonedDateTime_overrideChrono_matches() {
    MinguoDate mdt = MinguoDate.of(100, 6, 30);
    ChronoZonedDateTime<MinguoDate> mzdt = mdt.atTime(LocalTime.NOON).atZone(EUROPE_PARIS);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(mzdt)).toFormatter();
    f = f.withChronology(MinguoChronology.INSTANCE);
    TemporalAccessor accessor = f.parse("1234567890");
    assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.from(mdt));
    assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.NOON);
    assertEquals(accessor.query(TemporalQueries.chronology()), MinguoChronology.INSTANCE);
    assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_PARIS);
}
Also used : MinguoDate(java.time.chrono.MinguoDate) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 23 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatters method test_print_isoOffsetTime.

@Test(dataProvider = "sample_isoOffsetTime")
public void test_print_isoOffsetTime(Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId, String expected, Class<?> expectedEx) {
    TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
    if (expectedEx == null) {
        assertEquals(DateTimeFormatter.ISO_OFFSET_TIME.format(test), expected);
    } else {
        try {
            DateTimeFormatter.ISO_OFFSET_TIME.format(test);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) DateTimeParseException(java.time.format.DateTimeParseException) Test(org.testng.annotations.Test)

Example 24 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatters method test_print_basicIsoDate_fields.

@Test
public void test_print_basicIsoDate_fields() {
    TemporalAccessor test = buildAccessor(LocalDate.of(2008, 6, 3), null, null);
    assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603");
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Test(org.testng.annotations.Test)

Example 25 with TemporalAccessor

use of java.time.temporal.TemporalAccessor in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatters method test_parse_weekDate_largeYear.

@Test
public void test_parse_weekDate_largeYear() {
    TemporalAccessor parsed = DateTimeFormatter.ISO_WEEK_DATE.parseUnresolved("+123456-W04-5", new ParsePosition(0));
    assertEquals(parsed.getLong(IsoFields.WEEK_BASED_YEAR), 123456L);
    assertEquals(parsed.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR), 4L);
    assertEquals(parsed.getLong(DAY_OF_WEEK), 5L);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Aggregations

TemporalAccessor (java.time.temporal.TemporalAccessor)235 Test (org.testng.annotations.Test)189 DateTimeFormatter (java.time.format.DateTimeFormatter)103 ParsePosition (java.text.ParsePosition)82 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)61 DateTimeException (java.time.DateTimeException)32 DateTimeParseException (java.time.format.DateTimeParseException)24 LocalDate (java.time.LocalDate)14 TemporalField (java.time.temporal.TemporalField)13 ZonedDateTime (java.time.ZonedDateTime)7 LocalTime (java.time.LocalTime)6 InvalidParametersEvent (org.kie.dmn.feel.runtime.events.InvalidParametersEvent)6 Instant (java.time.Instant)5 ZoneId (java.time.ZoneId)5 ChronoLocalDate (java.time.chrono.ChronoLocalDate)5 Chronology (java.time.chrono.Chronology)5 ResolverStyle (java.time.format.ResolverStyle)5 Test (org.junit.Test)5 LocalDateTime (java.time.LocalDateTime)4 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)4