Skip to content

Commit 659f60f

Browse files
authored
Add missing ZonedDateTime methods for joda compat layer (#44829)
While joda no longer exists in the apis for 7.x, the compatibility layer still exists with helper methods mimicking the behavior of joda for ZonedDateTime objects returned for date fields in scripts. This layer was originally intended to be removed in 7.0, but is now likely to exist for the lifetime of 7.x. This commit adds missing methods from ChronoZonedDateTime to the compat class. These methods were not part of joda, but are needed to act like a real ZonedDateTime. relates #44411
1 parent 280b40e commit 659f60f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt

+11
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ class org.elasticsearch.script.JodaCompatibleZonedDateTime {
127127
ZonedDateTime withZoneSameLocal(ZoneId)
128128
ZonedDateTime withZoneSameInstant(ZoneId)
129129

130+
#### ChronoZonedDateTime
131+
int compareTo(JodaCompatibleZonedDateTime)
132+
Chronology getChronology()
133+
String format(DateTimeFormatter)
134+
int get(TemporalField)
135+
long getLong(TemporalField)
136+
ZoneOffset getOffset()
137+
boolean isSupported(TemporalField)
138+
long toEpochSecond()
139+
LocalTime toLocalTime()
140+
130141
#### Joda methods that exist in java time
131142
boolean equals(Object)
132143
int hashCode()

server/src/main/java/org/elasticsearch/script/JodaCompatibleZonedDateTime.java

+42
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@
3232
import java.time.Instant;
3333
import java.time.LocalDate;
3434
import java.time.LocalDateTime;
35+
import java.time.LocalTime;
3536
import java.time.Month;
3637
import java.time.OffsetDateTime;
3738
import java.time.ZoneId;
39+
import java.time.ZoneOffset;
3840
import java.time.ZonedDateTime;
41+
import java.time.chrono.Chronology;
42+
import java.time.format.DateTimeFormatter;
3943
import java.time.temporal.ChronoField;
4044
import java.time.temporal.TemporalAdjuster;
4145
import java.time.temporal.TemporalAmount;
@@ -94,6 +98,42 @@ public String toString() {
9498
return DATE_FORMATTER.format(dt);
9599
}
96100

101+
public String format(DateTimeFormatter formatter) {
102+
return dt.format(formatter);
103+
}
104+
105+
public int get(TemporalField field) {
106+
return dt.get(field);
107+
}
108+
109+
public long getLong(TemporalField field) {
110+
return dt.getLong(field);
111+
}
112+
113+
public Chronology getChronology() {
114+
return dt.getChronology();
115+
}
116+
117+
public int compareTo(JodaCompatibleZonedDateTime o) {
118+
return dt.compareTo(o.dt);
119+
}
120+
121+
public ZoneOffset getOffset() {
122+
return dt.getOffset();
123+
}
124+
125+
public boolean isSupported(TemporalField field) {
126+
return dt.isSupported(field);
127+
}
128+
129+
public long toEpochSecond() {
130+
return dt.toEpochSecond();
131+
}
132+
133+
public LocalTime toLocalTime() {
134+
return dt.toLocalTime();
135+
}
136+
97137
public boolean isAfter(JodaCompatibleZonedDateTime o) {
98138
return dt.isAfter(o.getZonedDateTime());
99139
}
@@ -106,6 +146,8 @@ public boolean isEqual(JodaCompatibleZonedDateTime o) {
106146
return dt.isEqual(o.getZonedDateTime());
107147
}
108148

149+
150+
109151
public int getDayOfMonth() {
110152
return dt.getDayOfMonth();
111153
}

0 commit comments

Comments
 (0)