diff --git a/vividus-plugin-datetime/src/main/java/org/vividus/datetime/expression/EpochExpressionProcessors.java b/vividus-plugin-datetime/src/main/java/org/vividus/datetime/expression/EpochExpressionProcessors.java index 53868911ed..053b606779 100644 --- a/vividus-plugin-datetime/src/main/java/org/vividus/datetime/expression/EpochExpressionProcessors.java +++ b/vividus-plugin-datetime/src/main/java/org/vividus/datetime/expression/EpochExpressionProcessors.java @@ -30,13 +30,16 @@ public class EpochExpressionProcessors extends DelegatingExpressionProcessor { + private static final DateTimeFormatter ISO_DATE_TIME_WITH_MILLIS_PRECISION = DateTimeFormatter.ofPattern( + "yyyy-MM-dd'T'HH:mm:ss.SSS"); + public EpochExpressionProcessors(DateUtils dateUtils) { super(List.of( toEpoch("toEpochSecond", dateUtils, ZonedDateTime::toEpochSecond), toEpoch("toEpochMilli", dateUtils, zdt -> zdt.toInstant().toEpochMilli()), - fromEpoch("fromEpochSecond", dateUtils::fromEpochSecond), - fromEpoch("fromEpochMilli", dateUtils::fromEpochMilli) + fromEpoch("fromEpochSecond", DateTimeFormatter.ISO_DATE_TIME, dateUtils::fromEpochSecond), + fromEpoch("fromEpochMilli", ISO_DATE_TIME_WITH_MILLIS_PRECISION, dateUtils::fromEpochMilli) )); } @@ -49,12 +52,12 @@ private static SingleArgExpressionProcessor toEpoch(String funtionName, }); } - private static SingleArgExpressionProcessor fromEpoch(String funtionName, + private static SingleArgExpressionProcessor fromEpoch(String funtionName, DateTimeFormatter formatter, LongFunction converter) { return new SingleArgExpressionProcessor<>(funtionName, arg -> { LocalDateTime localDateTime = converter.apply(new BigDecimal(arg).longValueExact()); - return DateTimeFormatter.ISO_DATE_TIME.format(localDateTime); + return formatter.format(localDateTime); }); } } diff --git a/vividus-plugin-datetime/src/test/java/org/vividus/datetime/expression/EpochExpressionProcessorsTests.java b/vividus-plugin-datetime/src/test/java/org/vividus/datetime/expression/EpochExpressionProcessorsTests.java index a5a2171a01..74160981f5 100644 --- a/vividus-plugin-datetime/src/test/java/org/vividus/datetime/expression/EpochExpressionProcessorsTests.java +++ b/vividus-plugin-datetime/src/test/java/org/vividus/datetime/expression/EpochExpressionProcessorsTests.java @@ -64,7 +64,10 @@ void shouldExecuteMatchingExpressionFromEpochSecond(String epoch, String expecte @ParameterizedTest @CsvSource({ "1.669640468123E12, 2022-11-28T13:01:08.123", - "734918400987, 1993-04-16T00:00:00.987" + "734918400987, 1993-04-16T00:00:00.987", + "734918400980, 1993-04-16T00:00:00.980", + "734918400900, 1993-04-16T00:00:00.900", + "734918400000, 1993-04-16T00:00:00.000" }) void shouldExecuteMatchingExpressionFromEpochMilli(String epoch, String expectedDate) {