Search in sources :

Example 6 with DateTimeFormatter

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

the class TCKIsoFields method test_parse_quarters_LENIENT.

@Test(dataProvider = "quarter")
public void test_parse_quarters_LENIENT(LocalDate date, int doq, int qoy) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral('-').appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-').appendValue(IsoFields.DAY_OF_QUARTER).toFormatter().withResolverStyle(ResolverStyle.LENIENT);
    LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f);
    assertEquals(parsed, date);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 7 with DateTimeFormatter

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

the class TCKIsoFields method test_parse_parseLenientQuarter_LENIENT.

@Test(dataProvider = "parseLenientQuarter")
public void test_parse_parseLenientQuarter_LENIENT(String str, LocalDate expected, boolean smart) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':').appendValue(IsoFields.DAY_OF_QUARTER).toFormatter().withResolverStyle(ResolverStyle.LENIENT);
    LocalDate parsed = LocalDate.parse(str, f);
    assertEquals(parsed, expected);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 8 with DateTimeFormatter

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

the class TCKIsoFields method test_parse_parseLenientWeek_STRICT.

@Test(dataProvider = "parseLenientWeek", expectedExceptions = DateTimeParseException.class)
public void test_parse_parseLenientWeek_STRICT(String str, LocalDate expected, boolean smart) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':').appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(ResolverStyle.STRICT);
    LocalDate.parse(str, f);
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 9 with DateTimeFormatter

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

the class TCKIsoFields method test_parse_parseLenientQuarter_SMART.

@Test(dataProvider = "parseLenientQuarter")
public void test_parse_parseLenientQuarter_SMART(String str, LocalDate expected, boolean smart) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':').appendValue(IsoFields.DAY_OF_QUARTER).toFormatter().withResolverStyle(ResolverStyle.SMART);
    if (smart) {
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, expected);
    } else {
        try {
            LocalDate.parse(str, f);
            fail("Should have failed");
        } catch (DateTimeParseException ex) {
        // expected
        }
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 10 with DateTimeFormatter

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

the class TCKLocalTime method factory_parse_formatter.

//-----------------------------------------------------------------------
// parse(DateTimeFormatter)
//-----------------------------------------------------------------------
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
    LocalTime test = LocalTime.parse("14 30 40", f);
    assertEquals(test, LocalTime.of(14, 30, 40));
}
Also used : LocalTime(java.time.LocalTime) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Aggregations

DateTimeFormatter (java.time.format.DateTimeFormatter)908 Test (org.junit.Test)300 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)93 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)85 ZonedDateTime (java.time.ZonedDateTime)71 Instant (java.time.Instant)53 DateTimeParseException (java.time.format.DateTimeParseException)52 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