Search in sources :

Example 66 with DateTimeFormatter

use of java.time.format.DateTimeFormatter 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 67 with DateTimeFormatter

use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_withZone.

//-----------------------------------------------------------------------
@Test
public void test_withZone() {
    DateTimeFormatter test = fmt;
    assertEquals(test.getZone(), null);
    test = test.withZone(ZoneId.of("Europe/Paris"));
    assertEquals(test.getZone(), ZoneId.of("Europe/Paris"));
    test = test.withZone(ZoneOffset.UTC);
    assertEquals(test.getZone(), ZoneOffset.UTC);
    test = test.withZone(null);
    assertEquals(test.getZone(), null);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 68 with DateTimeFormatter

use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_withLocale_null.

@Test(expectedExceptions = NullPointerException.class)
public void test_withLocale_null() {
    DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    base.withLocale((Locale) null);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 69 with DateTimeFormatter

use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.

the class TCKDateTimeFormatter method test_toFormat_parseObject_StringParsePosition_nullParsePosition.

@Test(expectedExceptions = NullPointerException.class)
public void test_toFormat_parseObject_StringParsePosition_nullParsePosition() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.parseObject("ONE30", (ParsePosition) null);
}
Also used : Format(java.text.Format) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 70 with DateTimeFormatter

use of java.time.format.DateTimeFormatter 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)

Aggregations

DateTimeFormatter (java.time.format.DateTimeFormatter)905 Test (org.junit.Test)297 Test (org.testng.annotations.Test)272 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)229 TemporalAccessor (java.time.temporal.TemporalAccessor)205 LocalDate (java.time.LocalDate)142 ParsePosition (java.text.ParsePosition)94 LocalDateTime (java.time.LocalDateTime)92 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)85 ZonedDateTime (java.time.ZonedDateTime)71 Instant (java.time.Instant)53 DateTimeParseException (java.time.format.DateTimeParseException)50 ZoneId (java.time.ZoneId)39 TemporalField (java.time.temporal.TemporalField)39 WeekFields (java.time.temporal.WeekFields)36 AbstractTCKTest (tck.java.time.AbstractTCKTest)36 DateTimeException (java.time.DateTimeException)34 IOException (java.io.IOException)26 Format (java.text.Format)26 LocalTime (java.time.LocalTime)25