Search in sources :

Example 56 with DateTimeFormatterBuilder

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

the class TCKDateTimeParseResolver method test_fieldResolvesToChronoZonedDateTime_overrideChrono_wrongChrono.

@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoZonedDateTime_overrideChrono_wrongChrono() {
    ChronoZonedDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON).atZone(EUROPE_PARIS);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
    f = f.withChronology(MinguoChronology.INSTANCE);
    f.parse("1234567890");
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 57 with DateTimeFormatterBuilder

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

the class TCKDateTimeParseResolver method test_fieldResolvesToChronoLocalDate_overrideChrono_matches.

@Test
public void test_fieldResolvesToChronoLocalDate_overrideChrono_matches() {
    MinguoDate mdt = MinguoDate.of(100, 6, 30);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(mdt)).toFormatter();
    f = f.withChronology(MinguoChronology.INSTANCE);
    TemporalAccessor accessor = f.parse("1234567890");
    assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.from(mdt));
    assertEquals(accessor.query(TemporalQueries.localTime()), null);
    assertEquals(accessor.query(TemporalQueries.chronology()), MinguoChronology.INSTANCE);
}
Also used : MinguoDate(java.time.chrono.MinguoDate) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 58 with DateTimeFormatterBuilder

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

the class TCKDateTimeParseResolver method test_fieldResolvesToChronoZonedDateTime_overrideZone_wrongZone.

@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoZonedDateTime_overrideZone_wrongZone() {
    ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter();
    f = f.withZone(ZoneId.of("Europe/London"));
    f.parse("1234567890");
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 59 with DateTimeFormatterBuilder

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

the class TCKDateTimeParseResolver method test_fieldResolvesToChronoLocalDate_overrideChrono_wrongChrono.

@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoLocalDate_overrideChrono_wrongChrono() {
    ChronoLocalDate cld = ThaiBuddhistChronology.INSTANCE.dateNow();
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cld)).toFormatter();
    f = f.withChronology(MinguoChronology.INSTANCE);
    f.parse("1234567890");
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 60 with DateTimeFormatterBuilder

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

the class TCKDateTimeParseResolver method test_fieldResolvesToChronoZonedDateTime_noOverrideChrono_wrongChrono.

@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoZonedDateTime_noOverrideChrono_wrongChrono() {
    ChronoZonedDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON).atZone(EUROPE_PARIS);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
    f.parse("1234567890");
}
Also used : DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Aggregations

DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)122 Test (org.testng.annotations.Test)115 DateTimeFormatter (java.time.format.DateTimeFormatter)114 TemporalAccessor (java.time.temporal.TemporalAccessor)61 LocalDate (java.time.LocalDate)38 TemporalField (java.time.temporal.TemporalField)20 AbstractTCKTest (tck.java.time.AbstractTCKTest)18 WeekFields (java.time.temporal.WeekFields)17 ParsePosition (java.text.ParsePosition)14 DateTimeException (java.time.DateTimeException)12 DateTimeParseException (java.time.format.DateTimeParseException)10 Instant (java.time.Instant)8 ZonedDateTime (java.time.ZonedDateTime)5 ResolverStyle (java.time.format.ResolverStyle)5 BeforeMethod (org.testng.annotations.BeforeMethod)5 ChronoLocalDate (java.time.chrono.ChronoLocalDate)4 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)3 Chronology (java.time.chrono.Chronology)3 HijrahChronology (java.time.chrono.HijrahChronology)3 IsoChronology (java.time.chrono.IsoChronology)3