Search in sources :

Example 51 with DateTimeFormatterBuilder

use of java.time.format.DateTimeFormatterBuilder in project streamsx.health by IBMStreams.

the class VinesToObservationParser method readResolve.

public Object readResolve() throws ObjectStreamException {
    formatter = new DateTimeFormatterBuilder().appendPattern(DATE_TIME_PATTERN).toFormatter(Locale.ENGLISH);
    isMappingEnabled = Boolean.parseBoolean(mappingEnabledSupplier.get());
    try {
        InputStream inputStream = Resources.getResource(MAPPING_FILE).openStream();
        lookupTable = new VinesToStreamsCodeLookupTable(inputStream);
    } catch (Exception e) {
        ObjectStreamException ose = new ObjectStreamException() {

            private static final long serialVersionUID = 1L;
        };
        ose.addSuppressed(e);
        throw ose;
    }
    return this;
}
Also used : InputStream(java.io.InputStream) ObjectStreamException(java.io.ObjectStreamException) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) ParseException(java.text.ParseException) ObjectStreamException(java.io.ObjectStreamException) DateTimeParseException(java.time.format.DateTimeParseException)

Example 52 with DateTimeFormatterBuilder

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

the class TCKChronoPrinterParser method setUp.

@BeforeMethod
public void setUp() {
    builder = new DateTimeFormatterBuilder();
    pos = new ParsePosition(0);
}
Also used : DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) ParsePosition(java.text.ParsePosition) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 53 with DateTimeFormatterBuilder

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

the class TCKDateTimeParseResolver method test_resolveTwoToDate.

@Test(dataProvider = "resolveTwoToDate")
public void test_resolveTwoToDate(TemporalField field1, long value1, TemporalField field2, long value2, LocalDate expectedDate) {
    String str = value1 + " " + value2;
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).appendLiteral(' ').appendValue(field2).toFormatter();
    TemporalAccessor accessor = f.parse(str);
    assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
    assertEquals(accessor.query(TemporalQueries.localTime()), null);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 54 with DateTimeFormatterBuilder

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

the class TCKDateTimeParseResolver method test_fieldResolvesToChronoZonedDateTime_noOverrideChrono_matches.

//-------------------------------------------------------------------------
@Test
public void test_fieldResolvesToChronoZonedDateTime_noOverrideChrono_matches() {
    ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter();
    TemporalAccessor accessor = f.parse("1234567890");
    assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(2010, 6, 30));
    assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(12, 30));
    assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
    assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_PARIS);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) 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 55 with DateTimeFormatterBuilder

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

the class TCKDateTimeParseResolver method test_resolveFourToTime.

@Test(dataProvider = "resolveFourToTime")
public void test_resolveFourToTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(HOUR_OF_DAY, hour).parseDefaulting(MINUTE_OF_HOUR, min).parseDefaulting(SECOND_OF_MINUTE, sec).parseDefaulting(NANO_OF_SECOND, nano).toFormatter();
    ResolverStyle[] styles = (style != null ? new ResolverStyle[] { style } : ResolverStyle.values());
    for (ResolverStyle s : styles) {
        if (expectedTime != null) {
            TemporalAccessor accessor = f.withResolverStyle(s).parse("");
            assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
            assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
            assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
        } else {
            try {
                f.withResolverStyle(style).parse("");
                fail();
            } catch (DateTimeParseException ex) {
            // expected
            }
        }
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) TemporalAccessor(java.time.temporal.TemporalAccessor) ResolverStyle(java.time.format.ResolverStyle) 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