Search in sources :

Example 1 with DateTimeFormatterBuilder

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

the class TCKIsoFields method test_parse_weeks_STRICT.

//-----------------------------------------------------------------------
// parse weeks
//-----------------------------------------------------------------------
@Test(dataProvider = "week")
public void test_parse_weeks_STRICT(LocalDate date, DayOfWeek dow, int week, int wby) {
    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 parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), 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 2 with DateTimeFormatterBuilder

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

the class TCKJulianFields method test_samples_parse_STRICT.

//-----------------------------------------------------------------------
@Test(dataProvider = "samples")
public void test_samples_parse_STRICT(TemporalField field, LocalDate date, long value) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field).toFormatter().withResolverStyle(ResolverStyle.STRICT);
    LocalDate parsed = LocalDate.parse(Long.toString(value), 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) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 3 with DateTimeFormatterBuilder

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

the class TCKJulianFields method test_samples_parse_SMART.

@Test(dataProvider = "samples")
public void test_samples_parse_SMART(TemporalField field, LocalDate date, long value) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field).toFormatter().withResolverStyle(ResolverStyle.SMART);
    LocalDate parsed = LocalDate.parse(Long.toString(value), 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) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 4 with DateTimeFormatterBuilder

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

the class TCKJulianFields method test_samples_parse_LENIENT.

@Test(dataProvider = "samples")
public void test_samples_parse_LENIENT(TemporalField field, LocalDate date, long value) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field).toFormatter().withResolverStyle(ResolverStyle.LENIENT);
    LocalDate parsed = LocalDate.parse(Long.toString(value), 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) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 5 with DateTimeFormatterBuilder

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

Aggregations

DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)244 DateTimeFormatter (java.time.format.DateTimeFormatter)227 TemporalAccessor (java.time.temporal.TemporalAccessor)115 Test (org.testng.annotations.Test)115 Test (org.junit.Test)104 LocalDate (java.time.LocalDate)77 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)69 TemporalField (java.time.temporal.TemporalField)40 AbstractTCKTest (tck.java.time.AbstractTCKTest)36 WeekFields (java.time.temporal.WeekFields)34 DateTimeException (java.time.DateTimeException)26 ParsePosition (java.text.ParsePosition)25 DateTimeParseException (java.time.format.DateTimeParseException)20 Instant (java.time.Instant)16 ZonedDateTime (java.time.ZonedDateTime)10 ResolverStyle (java.time.format.ResolverStyle)10 LocalDateTime (java.time.LocalDateTime)6 ChronoLocalDate (java.time.chrono.ChronoLocalDate)6 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)6 Chronology (java.time.chrono.Chronology)5