Search in sources :

Example 16 with TemporalAccessor

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

the class TCKDateTimeFormatters method test_print_rfc1123_missingField.

@Test(expectedExceptions = DateTimeException.class)
public void test_print_rfc1123_missingField() {
    TemporalAccessor test = YearMonth.of(2008, 6);
    DateTimeFormatter.RFC_1123_DATE_TIME.format(test);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Test(org.testng.annotations.Test)

Example 17 with TemporalAccessor

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

the class TCKDateTimeParseResolver method test_parse_fromField_SecondOfDay.

// SPEC: ChronoField.SECOND_OF_DAY
@Test
public void test_parse_fromField_SecondOfDay() {
    DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();
    TemporalAccessor acc = fmt.parse("864");
    assertEquals(acc.isSupported(SECOND_OF_DAY), true);
    assertEquals(acc.isSupported(NANO_OF_SECOND), true);
    assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
    assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
    assertEquals(acc.getLong(SECOND_OF_DAY), 864L);
    assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
    assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
    assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 18 with TemporalAccessor

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

the class TCKDateTimeParseResolver method test_withChronology_parsedChronology_override.

@Test
public void test_withChronology_parsedChronology_override() {
    DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).appendChronologyId().toFormatter();
    f = f.withChronology(MinguoChronology.INSTANCE);
    TemporalAccessor accessor = f.parse("ThaiBuddhist");
    assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
    assertEquals(accessor.query(TemporalQueries.localTime()), null);
    assertEquals(accessor.query(TemporalQueries.chronology()), ThaiBuddhistChronology.INSTANCE);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 19 with TemporalAccessor

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

the class TCKDateTimeParseResolver method test_resolveOneToTime.

@Test(dataProvider = "resolveOneToTime")
public void test_resolveOneToTime(TemporalField field1, long value1, LocalTime expectedTime) {
    String str = Long.toString(value1);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
    TemporalAccessor accessor = f.parse(str);
    assertEquals(accessor.query(TemporalQueries.localDate()), null);
    assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 20 with TemporalAccessor

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

the class TCKDateTimeParseResolver method test_fieldResolvesToChronoLocalDateTime_noOverrideChrono_matches.

//-------------------------------------------------------------------------
@Test
public void test_fieldResolvesToChronoLocalDateTime_noOverrideChrono_matches() {
    LocalDateTime ldt = LocalDateTime.of(2010, 6, 30, 12, 30);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(ldt)).toFormatter();
    TemporalAccessor accessor = f.parse("1234567890");
    assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(2010, 6, 30));
    assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(12, 30));
    assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
}
Also used : ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalDateTime(java.time.LocalDateTime) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) 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