Search in sources :

Example 61 with TemporalAccessor

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

the class TCKChronoPrinterParser method test_parseValid_caseSensitive_lowercaseRejected.

@Test(dataProvider = "parseValid")
public void test_parseValid_caseSensitive_lowercaseRejected(String text, Chronology expected) {
    builder.appendChronologyId();
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text.toLowerCase(Locale.ENGLISH), pos);
    assertEquals(pos.getIndex(), 0);
    assertEquals(pos.getErrorIndex(), 0);
    assertEquals(parsed, null);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Test(org.testng.annotations.Test)

Example 62 with TemporalAccessor

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

the class TCKChronoPrinterParser method test_parseValid_caseInsensitive.

@Test(dataProvider = "parseValid")
public void test_parseValid_caseInsensitive(String text, Chronology expected) {
    builder.parseCaseInsensitive().appendChronologyId();
    TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text.toLowerCase(Locale.ENGLISH), pos);
    assertEquals(pos.getIndex(), expected.getId().length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(parsed.query(TemporalQueries.chronology()), expected);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Test(org.testng.annotations.Test)

Example 63 with TemporalAccessor

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

the class TCKDateTimeFormatter method test_parseBest_firstOption.

//-----------------------------------------------------------------------
@Test
public void test_parseBest_firstOption() throws Exception {
    DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm[XXX]");
    TemporalAccessor result = test.parseBest("2011-06-30 12:30+03:00", ZonedDateTime::from, LocalDateTime::from);
    LocalDateTime ldt = LocalDateTime.of(2011, 6, 30, 12, 30);
    assertEquals(result, ZonedDateTime.of(ldt, ZoneOffset.ofHours(3)));
}
Also used : LocalDateTime(java.time.LocalDateTime) TemporalAccessor(java.time.temporal.TemporalAccessor) ZonedDateTime(java.time.ZonedDateTime) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 64 with TemporalAccessor

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

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_parseError.

@Test
public void test_toFormat_parseObject_StringParsePosition_parseError() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONEXXX", pos);
    // TODO: is this right?
    assertEquals(pos.getIndex(), 0);
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
Also used : Format(java.text.Format) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 65 with TemporalAccessor

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

the class TCKDateTimeFormatter method test_parseUnresolved_StringParsePosition_parseError.

@Test
public void test_parseUnresolved_StringParsePosition_parseError() {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = test.parseUnresolved("ONEXXX", pos);
    assertEquals(pos.getIndex(), 0);
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) 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