Skip to content

Commit 84b882e

Browse files
committed
Add extra cases to dateCases
1 parent 44ad461 commit 84b882e

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@
4747
import java.util.Collections;
4848
import java.util.List;
4949
import java.util.Map;
50+
import java.util.function.BiConsumer;
5051
import java.util.function.BiFunction;
5152
import java.util.function.BinaryOperator;
53+
import java.util.function.Consumer;
5254
import java.util.function.DoubleFunction;
5355
import java.util.function.Function;
5456
import java.util.function.IntFunction;
@@ -1159,9 +1161,16 @@ public static List<TypedDataSupplier> dateCases(Instant min, Instant max) {
11591161
*/
11601162
public static List<TypedDataSupplier> dateCases(long min, long max) {
11611163
List<TypedDataSupplier> cases = new ArrayList<>();
1162-
if (min <= 0 && max >= 0) {
1163-
cases.add(new TypedDataSupplier("<1970-01-01T00:00:00Z>", () -> 0L, DataType.DATETIME));
1164-
}
1164+
Consumer<String> addExactCase = (value) -> {
1165+
long date = Instant.parse(value).toEpochMilli();
1166+
if (date >= min && date <= max) {
1167+
cases.add(new TypedDataSupplier("<" + value + ">", () -> date, DataType.DATETIME));
1168+
}
1169+
};
1170+
1171+
addExactCase.accept("1970-01-01T00:00:00Z");
1172+
addExactCase.accept("2025-03-30T01:00:00+01:00"); // Before Europe/Paris DST change
1173+
addExactCase.accept("2025-03-30T03:00:00+02:00"); // After Europe/Paris DST change
11651174

11661175
// 1970-01-01T00:00:00Z - 2286-11-20T17:46:40Z
11671176
long lower1 = Math.max(min, 0);
@@ -1186,6 +1195,8 @@ public static List<TypedDataSupplier> dateCases(long min, long max) {
11861195
);
11871196
}
11881197

1198+
1199+
11891200
return cases;
11901201
}
11911202

@@ -1218,11 +1229,17 @@ public static List<TypedDataSupplier> dateNanosCases(Instant minValue, Instant m
12181229
Instant twentyTwoFifty = Instant.parse("2250-01-01T00:00:00Z");
12191230

12201231
List<TypedDataSupplier> cases = new ArrayList<>();
1221-
if (minValue.isAfter(Instant.EPOCH) == false) {
1222-
cases.add(
1223-
new TypedDataSupplier("<1970-01-01T00:00:00.000000000Z>", () -> DateUtils.toLong(Instant.EPOCH), DataType.DATE_NANOS)
1224-
);
1225-
}
1232+
Consumer<String> addExactCase = (value) -> {
1233+
Instant instant = Instant.parse(value);
1234+
long date = DateUtils.toLong(Instant.parse(value));
1235+
if (minValue.isAfter(instant) == false && maxValue.isBefore(instant) == false) {
1236+
cases.add(new TypedDataSupplier("<" + value + ">", () -> date, DataType.DATE_NANOS));
1237+
}
1238+
};
1239+
1240+
addExactCase.accept("1970-01-01T00:00:00.000000000Z");
1241+
addExactCase.accept("2025-03-30T01:00:00.000000001+01:00"); // Before Europe/Paris DST change
1242+
addExactCase.accept("2025-03-30T03:00:00.000000002+02:00"); // After Europe/Paris DST change
12261243

12271244
Instant lower = Instant.EPOCH.isBefore(minValue) ? minValue : Instant.EPOCH;
12281245
Instant upper = twentyOneHundred.isAfter(maxValue) ? maxValue : twentyOneHundred;

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateTruncTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static List<PeriodTestCaseData> makeTruncPeriodTestCases() {
173173
new PeriodTestCaseData(Period.ofDays(1), "2024-03-01T00:30:00Z", "-03", "2024-02-29T03:00:00Z"),
174174

175175
///
176-
/// Timezone with DST (-5 to -4 at 2025-03-09T02:00:00-05, and -4 to -5 at 2025-11-02T02:00:00-04)
176+
/// Timezone with DST (e.g. New York: -5 to -4 at 2025-03-09T02:00:00-05, and -4 to -5 at 2025-11-02T02:00:00-04)
177177
///
178178
new PeriodTestCaseData(Period.ofDays(1), "2025-03-09T06:00:00-04:00", "America/New_York", "2025-03-09T00:00:00-05:00"),
179179
new PeriodTestCaseData(Period.ofMonths(1), "2025-03-09T06:00:00-04:00", "America/New_York", "2025-03-01T00:00:00-05:00"),
@@ -182,6 +182,8 @@ public static List<PeriodTestCaseData> makeTruncPeriodTestCases() {
182182
new PeriodTestCaseData(Period.ofDays(1), "2025-11-02T05:00:00-05:00", "America/New_York", "2025-11-02T00:00:00-04:00"),
183183
new PeriodTestCaseData(Period.ofDays(7), "2025-11-02T05:00:00-05:00", "America/New_York", "2025-10-27T00:00:00-04:00"),
184184
new PeriodTestCaseData(Period.ofMonths(3), "2025-11-02T05:00:00-05:00", "America/New_York", "2025-10-01T00:00:00-04:00"),
185+
new PeriodTestCaseData(Period.ofDays(1), "2025-10-26T02:00:00+02:00", "Europe/Rome", "2025-10-26T00:00:00+02:00"),
186+
new PeriodTestCaseData(Period.ofMonths(3), "2025-11-02T05:00:00-05:00", "Europe/Rome", "2025-10-01T00:00:00-04:00"),
185187

186188
///
187189
/// Partial hours timezones

0 commit comments

Comments
 (0)