use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TestReducedPrinter method test_printAdjacent.
@Test(dataProvider = "PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
builder = new DateTimeFormatterBuilder();
builder.appendPattern(pattern);
DateTimeFormatter dtf = builder.toFormatter();
LocalDate ld = LocalDate.of(year, month, day);
String actual = dtf.format(ld);
assertEquals(actual, text, "formatter output: " + dtf);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_reducedWithLateChronoChangeTwice.
@Test
public void test_reducedWithLateChronoChangeTwice() {
DateTimeFormatter df = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1)).appendLiteral(" ").appendChronologyId().appendLiteral(" ").appendChronologyId().toFormatter();
int expected = 2044;
String input = "44 ThaiBuddhist ISO";
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = df.parseUnresolved(input, pos);
assertEquals(pos.getIndex(), input.length(), "Input not parsed completely: " + pos);
assertEquals(pos.getErrorIndex(), -1, "Error index should be -1 (no-error)");
int actual = parsed.get(YEAR);
assertEquals(actual, expected, String.format("Wrong date parsed, chrono: %s, input: %s", parsed.query(TemporalQueries.chronology()), input));
}
use of java.time.format.DateTimeFormatterBuilder in project nifi by apache.
the class TimeAdapter method unmarshal.
@Override
public Date unmarshal(String date) throws Exception {
final LocalDateTime now = LocalDateTime.now();
final DateTimeFormatter parser = new DateTimeFormatterBuilder().appendPattern(DEFAULT_TIME_FORMAT).parseDefaulting(ChronoField.YEAR, now.getYear()).parseDefaulting(ChronoField.MONTH_OF_YEAR, now.getMonthValue()).parseDefaulting(ChronoField.DAY_OF_MONTH, now.getDayOfMonth()).parseDefaulting(ChronoField.MILLI_OF_SECOND, 0).toFormatter(Locale.US);
final LocalDateTime parsedDateTime = LocalDateTime.parse(date, parser);
return Date.from(parsedDateTime.toInstant(ZONE_ID.getRules().getOffset(now)));
}
use of java.time.format.DateTimeFormatterBuilder in project nifi by apache.
the class TimezoneAdapter method unmarshal.
@Override
public Date unmarshal(String date) throws Exception {
final LocalDateTime now = LocalDateTime.now();
final DateTimeFormatter parser = new DateTimeFormatterBuilder().appendPattern(DEFAULT_DATE_TIME_FORMAT).parseDefaulting(ChronoField.YEAR, now.getYear()).parseDefaulting(ChronoField.MONTH_OF_YEAR, now.getMonthValue()).parseDefaulting(ChronoField.DAY_OF_MONTH, now.getDayOfMonth()).parseDefaulting(ChronoField.HOUR_OF_DAY, now.getHour()).parseDefaulting(ChronoField.MINUTE_OF_HOUR, now.getMinute()).parseDefaulting(ChronoField.SECOND_OF_MINUTE, now.getSecond()).parseDefaulting(ChronoField.MILLI_OF_SECOND, 0).toFormatter(Locale.US);
final LocalDateTime parsedDateTime = LocalDateTime.parse(date, parser);
return Date.from(parsedDateTime.toInstant(ZONE_ID.getRules().getOffset(now)));
}
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;
}
Aggregations