use of java.time.Period in project drools by kiegroup.
the class TypeUtil method formatValue.
public static String formatValue(final Object val, final boolean wrapForCodeUsage) {
if (val instanceof String) {
return formatString(val.toString(), wrapForCodeUsage);
} else if (val instanceof LocalDate) {
return formatDate((LocalDate) val, wrapForCodeUsage);
} else if (val instanceof LocalTime || val instanceof OffsetTime) {
return formatTimeString(TimeFunction.FEEL_TIME.format((TemporalAccessor) val), wrapForCodeUsage);
} else if (val instanceof LocalDateTime || val instanceof OffsetDateTime) {
return formatDateTimeString(DateAndTimeFunction.FEEL_DATE_TIME.format((TemporalAccessor) val), wrapForCodeUsage);
} else if (val instanceof ZonedDateTime) {
TemporalAccessor ta = (TemporalAccessor) val;
ZoneId zone = ta.query(TemporalQueries.zone());
if (!(zone instanceof ZoneOffset)) {
// it is a ZoneRegion
return formatDateTimeString(DateAndTimeFunction.REGION_DATETIME_FORMATTER.format((TemporalAccessor) val), wrapForCodeUsage);
} else {
return formatDateTimeString(DateAndTimeFunction.FEEL_DATE_TIME.format((TemporalAccessor) val), wrapForCodeUsage);
}
} else if (val instanceof Duration) {
return formatDuration((Duration) val, wrapForCodeUsage);
} else if (val instanceof Period) {
return formatPeriod((Period) val, wrapForCodeUsage);
} else if (val instanceof TemporalAccessor) {
TemporalAccessor ta = (TemporalAccessor) val;
if (ta.query(TemporalQueries.localDate()) == null && ta.query(TemporalQueries.localTime()) != null && ta.query(TemporalQueries.zoneId()) != null) {
return formatTimeString(TimeFunction.FEEL_TIME.format((TemporalAccessor) val), wrapForCodeUsage);
} else {
return String.valueOf(val);
}
} else if (val instanceof List) {
return formatList((List) val, wrapForCodeUsage);
} else if (val instanceof Range) {
return formatRange((Range) val, wrapForCodeUsage);
} else if (val instanceof Map) {
return formatContext((Map) val, wrapForCodeUsage);
} else {
return String.valueOf(val);
}
}
use of java.time.Period in project drools by kiegroup.
the class DMNRuntimeTest method testYearsAndMonthsDuration.
@Test
public void testYearsAndMonthsDuration() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("yearMonthDuration.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_6eda1490-21ca-441e-8a26-ab3ca800e43c", "Drawing 1");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
BuiltInType feelType = (BuiltInType) BuiltInType.determineTypeFromName("yearMonthDuration");
Period period = (Period) feelType.fromString("P2Y1M");
DMNContext context = runtime.newContext();
context.set("iDuration", period);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
DMNContext result = dmnResult.getContext();
assertThat(result.get("How long"), is("Longer than a year"));
}
use of java.time.Period in project drbookings by DrBookings.
the class PeriodTest method testOneMonthPeriodDays01.
@Test
public void testOneMonthPeriodDays01() {
final Period p = Period.between(LocalDate.of(2017, 06, 01), LocalDate.of(2017, 07, 01));
assertEquals(0, p.getDays());
}
use of java.time.Period in project jdbi by jdbi.
the class TestPeriod method testNegativePeriod.
@Test
public void testNegativePeriod() {
handle.execute("insert into intervals(id, foo) values(?, interval '-3 years -1 month 2 days')", 7);
final Period p = handle.createQuery("select foo from intervals where id=?").bind(0, 7).mapTo(Period.class).findOnly();
assertThat(p).isEqualTo(Period.of(-3, -1, 2));
}
use of java.time.Period in project learnjava8 by mkdika.
the class Period1 method main.
/* Java 8 Date Time API:
---------------------
java.time.Period
*/
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2015, 10, 13);
LocalDate date2 = LocalDate.now();
Period period1 = Period.between(date1, date2);
System.out.println("Date1: " + date1);
System.out.println("Date2: " + date2);
System.out.println("Periode (date1 to date2): " + period1);
System.out.println("\tYears: " + period1.getYears());
System.out.println("\tMonths: " + period1.getMonths());
System.out.println("\tDays: " + period1.getDays());
}
Aggregations