Skip to content

Commit 1b2ce2a

Browse files
Fix serialization
1 parent f253a14 commit 1b2ce2a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

server/src/main/java/org/elasticsearch/common/Rounding.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ long extraLocalOffsetLookup() {
172172
return ratio;
173173
}
174174
},
175-
YEARS_OF_CENTURY((byte) 9, "year", ChronoField.YEAR_OF_ERA, false, 12) {
175+
YEARS_OF_CENTURY((byte) 9, "years", ChronoField.YEAR_OF_ERA, false, 12) {
176176
private final long extraLocalOffsetLookup = TimeUnit.DAYS.toMillis(366);
177177

178178
@Override
@@ -185,7 +185,7 @@ long extraLocalOffsetLookup() {
185185
return extraLocalOffsetLookup;
186186
}
187187
},
188-
MONTHS_OF_YEAR((byte) 10, "month", ChronoField.MONTH_OF_YEAR, false, 1) {
188+
MONTHS_OF_YEAR((byte) 10, "months", ChronoField.MONTH_OF_YEAR, false, 1) {
189189
private final long extraLocalOffsetLookup = TimeUnit.DAYS.toMillis(31);
190190

191191
@Override
@@ -551,6 +551,12 @@ private LocalDateTime truncateLocalDateTime(LocalDateTime localDateTime) {
551551
case YEAR_OF_CENTURY:
552552
return LocalDateTime.of(LocalDate.of(localDateTime.getYear(), 1, 1), LocalTime.MIDNIGHT);
553553

554+
case YEARS_OF_CENTURY:
555+
return LocalDateTime.of(LocalDate.of(localDateTime.getYear(), 1, 1), LocalTime.MIDNIGHT);
556+
557+
case MONTHS_OF_YEAR:
558+
return LocalDateTime.of(localDateTime.getYear(), localDateTime.getMonthValue(), 1, 0, 0);
559+
554560
default:
555561
throw new IllegalArgumentException("NOT YET IMPLEMENTED for unit " + unit);
556562
}
@@ -913,6 +919,8 @@ private LocalDateTime nextRelevantMidnight(LocalDateTime localMidnight) {
913919
case MONTH_OF_YEAR -> localMidnight.plus(1, ChronoUnit.MONTHS);
914920
case QUARTER_OF_YEAR -> localMidnight.plus(3, ChronoUnit.MONTHS);
915921
case YEAR_OF_CENTURY -> localMidnight.plus(1, ChronoUnit.YEARS);
922+
case YEARS_OF_CENTURY -> localMidnight.plus(1, ChronoUnit.YEARS);
923+
case MONTHS_OF_YEAR -> localMidnight.plus(1, ChronoUnit.MONTHS);
916924
default -> throw new IllegalArgumentException("Unknown round-to-midnight unit: " + unit);
917925
};
918926
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public class DateHistogramAggregationBuilder extends ValuesSourceAggregationBuil
7070
entry("minute", Rounding.DateTimeUnit.MINUTE_OF_HOUR),
7171
entry("1m", Rounding.DateTimeUnit.MINUTE_OF_HOUR),
7272
entry("second", Rounding.DateTimeUnit.SECOND_OF_MINUTE),
73-
entry("1s", Rounding.DateTimeUnit.SECOND_OF_MINUTE)
73+
entry("1s", Rounding.DateTimeUnit.SECOND_OF_MINUTE),
74+
entry("years", Rounding.DateTimeUnit.YEARS_OF_CENTURY),
75+
entry("months", Rounding.DateTimeUnit.MONTHS_OF_YEAR)
7476
);
7577

7678
public static final ObjectParser<DateHistogramAggregationBuilder, String> PARSER = ObjectParser.fromBuilder(

0 commit comments

Comments
 (0)