Search in sources :

Example 66 with TemporalAccessor

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

the class TCKDateTimeFormatter method test_resolverFields_listOfOneMatching.

@Test
public void test_resolverFields_listOfOneMatching() throws Exception {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).toFormatter().withResolverFields(YEAR);
    TemporalAccessor parsed = f.parse("2012");
    assertEquals(parsed.isSupported(YEAR), true);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 67 with TemporalAccessor

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

the class TCKDateTimeFormatter method test_parse_CharSequence_ParsePosition_resolved.

@Test
public void test_parse_CharSequence_ParsePosition_resolved() {
    DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
    ParsePosition pos = new ParsePosition(3);
    TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos);
    assertEquals(pos.getIndex(), 13);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.isSupported(YEAR), true);
    assertEquals(result.isSupported(MONTH_OF_YEAR), true);
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.isSupported(HOUR_OF_DAY), false);
    assertEquals(result.getLong(YEAR), 2012L);
    assertEquals(result.getLong(MONTH_OF_YEAR), 6L);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
    assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30));
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 68 with TemporalAccessor

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

the class TCKDateTimeFormatter method test_resolverFields_listOfOneNotMatching.

@Test
public void test_resolverFields_listOfOneNotMatching() throws Exception {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).toFormatter().withResolverFields(MONTH_OF_YEAR);
    TemporalAccessor parsed = f.parse("2012");
    // not in the list of resolverFields
    assertEquals(parsed.isSupported(YEAR), false);
    assertEquals(parsed.isSupported(MONTH_OF_YEAR), false);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 69 with TemporalAccessor

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

the class AbstractDateTimeTest method basicTest_get_TemporalField_null.

@Test()
public void basicTest_get_TemporalField_null() {
    for (TemporalAccessor sample : samples()) {
        try {
            sample.get(null);
            fail("Failed on " + sample);
        } catch (NullPointerException ex) {
        // expected
        }
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Test(org.testng.annotations.Test)

Example 70 with TemporalAccessor

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

the class AbstractDateTimeTest method basicTest_getLong_TemporalField_unsupported.

@Test()
public void basicTest_getLong_TemporalField_unsupported() {
    for (TemporalAccessor sample : samples()) {
        for (TemporalField field : invalidFields()) {
            try {
                sample.getLong(field);
                fail("Failed on " + sample + " " + field);
            } catch (DateTimeException ex) {
            // expected
            }
        }
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) 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