Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin-datetime] Add trailing zero millis by fromEpochMilli expression #4930

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
));
}

Expand All @@ -49,12 +52,12 @@ private static SingleArgExpressionProcessor<String> toEpoch(String funtionName,
});
}

private static SingleArgExpressionProcessor<String> fromEpoch(String funtionName,
private static SingleArgExpressionProcessor<String> fromEpoch(String funtionName, DateTimeFormatter formatter,
LongFunction<LocalDateTime> 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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading