Search in sources :

Example 36 with TemporalAccessor

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

the class TCKDateTimeFormatterBuilder method test_adjacent_strict_fractionFollows.

//-----------------------------------------------------------------------
@Test
public void test_adjacent_strict_fractionFollows() throws Exception {
    // succeeds because hour/min are fixed width
    DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 0, 3, false).toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("1230567", pp);
    assertEquals(pp.getErrorIndex(), -1);
    assertEquals(pp.getIndex(), 7);
    assertEquals(parsed.getLong(HOUR_OF_DAY), 12L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L);
    assertEquals(parsed.getLong(NANO_OF_SECOND), 567_000_000L);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 37 with TemporalAccessor

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

the class TCKDateTimeFormatterBuilder method test_adjacent_lenient_firstVariableWidth_success.

@Test
public void test_adjacent_lenient_firstVariableWidth_success() throws Exception {
    // succeeds greedily parsing variable width, then fixed width, to non-numeric Z
    DateTimeFormatter f = builder.parseLenient().appendValue(HOUR_OF_DAY).appendValue(MINUTE_OF_HOUR, 2).appendLiteral('Z').toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("12309Z", pp);
    assertEquals(pp.getErrorIndex(), -1);
    assertEquals(pp.getIndex(), 6);
    assertEquals(parsed.getLong(HOUR_OF_DAY), 123L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR), 9L);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 38 with TemporalAccessor

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

the class TCKDateTimeFormatterBuilder method test_adjacent_lenient_fractionFollows_0digit.

@Test
public void test_adjacent_lenient_fractionFollows_0digit() throws Exception {
    // succeeds because hour/min are fixed width
    DateTimeFormatter f = builder.parseLenient().appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 3, 3, false).toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("1230", pp);
    assertEquals(pp.getErrorIndex(), -1);
    assertEquals(pp.getIndex(), 4);
    assertEquals(parsed.getLong(HOUR_OF_DAY), 12L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 39 with TemporalAccessor

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

the class TCKDateTimeFormatterBuilder method test_adjacent_strict_firstVariableWidth_success.

@Test
public void test_adjacent_strict_firstVariableWidth_success() throws Exception {
    // succeeds greedily parsing variable width, then fixed width, to non-numeric Z
    DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY).appendValue(MINUTE_OF_HOUR, 2).appendLiteral('Z').toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("12309Z", pp);
    assertEquals(pp.getErrorIndex(), -1);
    assertEquals(pp.getIndex(), 6);
    assertEquals(parsed.getLong(HOUR_OF_DAY), 123L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR), 9L);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) ParsePosition(java.text.ParsePosition) Test(org.testng.annotations.Test)

Example 40 with TemporalAccessor

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

the class TCKDateTimeFormatterBuilder method test_adjacent_strict_fractionFollows_2digit.

@Test
public void test_adjacent_strict_fractionFollows_2digit() throws Exception {
    // succeeds because hour/min are fixed width
    DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendFraction(NANO_OF_SECOND, 0, 3, false).toFormatter(Locale.UK);
    ParsePosition pp = new ParsePosition(0);
    TemporalAccessor parsed = f.parseUnresolved("123056", pp);
    assertEquals(pp.getErrorIndex(), -1);
    assertEquals(pp.getIndex(), 6);
    assertEquals(parsed.getLong(HOUR_OF_DAY), 12L);
    assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L);
    assertEquals(parsed.getLong(NANO_OF_SECOND), 560_000_000L);
}
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