@@ -47,7 +47,7 @@ final public class ElasticsearchDateConverter {
47
47
48
48
/**
49
49
* Creates an ElasticsearchDateConverter for the given {@link DateFormat}.
50
- *
50
+ *
51
51
* @param dateFormat must not be @{literal null}
52
52
* @return converter
53
53
*/
@@ -135,7 +135,7 @@ public Date parse(String input) {
135
135
/**
136
136
* Creates a {@link DateFormatter} for a given pattern. The pattern can be the name of a {@link DateFormat} enum value
137
137
* or a literal pattern.
138
- *
138
+ *
139
139
* @param pattern the pattern to use
140
140
* @return DateFormatter
141
141
*/
@@ -172,8 +172,73 @@ private static DateFormatter forPattern(String pattern) {
172
172
return new PatternDateFormatter (dateTimeFormatter );
173
173
}
174
174
175
+ @ SuppressWarnings ("unchecked" )
175
176
private static <T extends TemporalAccessor > TemporalQuery <T > getTemporalQuery (Class <T > type ) {
176
177
return temporal -> {
178
+ // no reflection for java.time classes (GraalVM native)
179
+ if (type == java .time .chrono .HijrahDate .class ) {
180
+ return (T ) java .time .chrono .HijrahDate .from (temporal );
181
+ }
182
+ if (type == java .time .chrono .JapaneseDate .class ) {
183
+ return (T ) java .time .chrono .JapaneseDate .from (temporal );
184
+ }
185
+ if (type == java .time .ZonedDateTime .class ) {
186
+ return (T ) java .time .ZonedDateTime .from (temporal );
187
+ }
188
+ if (type == java .time .LocalDateTime .class ) {
189
+ return (T ) java .time .LocalDateTime .from (temporal );
190
+ }
191
+ if (type == java .time .chrono .ThaiBuddhistDate .class ) {
192
+ return (T ) java .time .chrono .ThaiBuddhistDate .from (temporal );
193
+ }
194
+ if (type == java .time .LocalTime .class ) {
195
+ return (T ) java .time .LocalTime .from (temporal );
196
+ }
197
+ if (type == java .time .ZoneOffset .class ) {
198
+ return (T ) java .time .ZoneOffset .from (temporal );
199
+ }
200
+ if (type == java .time .OffsetTime .class ) {
201
+ return (T ) java .time .OffsetTime .from (temporal );
202
+ }
203
+ if (type == java .time .chrono .ChronoLocalDate .class ) {
204
+ return (T ) java .time .chrono .ChronoLocalDate .from (temporal );
205
+ }
206
+ if (type == java .time .Month .class ) {
207
+ return (T ) java .time .Month .from (temporal );
208
+ }
209
+ if (type == java .time .chrono .ChronoLocalDateTime .class ) {
210
+ return (T ) java .time .chrono .ChronoLocalDateTime .from (temporal );
211
+ }
212
+ if (type == java .time .MonthDay .class ) {
213
+ return (T ) java .time .MonthDay .from (temporal );
214
+ }
215
+ if (type == java .time .Instant .class ) {
216
+ return (T ) java .time .Instant .from (temporal );
217
+ }
218
+ if (type == java .time .OffsetDateTime .class ) {
219
+ return (T ) java .time .OffsetDateTime .from (temporal );
220
+ }
221
+ if (type == java .time .chrono .ChronoZonedDateTime .class ) {
222
+ return (T ) java .time .chrono .ChronoZonedDateTime .from (temporal );
223
+ }
224
+ if (type == java .time .chrono .MinguoDate .class ) {
225
+ return (T ) java .time .chrono .MinguoDate .from (temporal );
226
+ }
227
+ if (type == java .time .Year .class ) {
228
+ return (T ) java .time .Year .from (temporal );
229
+ }
230
+ if (type == java .time .DayOfWeek .class ) {
231
+ return (T ) java .time .DayOfWeek .from (temporal );
232
+ }
233
+ if (type == java .time .LocalDate .class ) {
234
+ return (T ) java .time .LocalDate .from (temporal );
235
+ }
236
+ if (type == java .time .YearMonth .class ) {
237
+ return (T ) java .time .YearMonth .from (temporal );
238
+ }
239
+
240
+ // for implementations not covered until here use reflection to check for the existence of a static
241
+ // from(TemporalAccessor) method
177
242
try {
178
243
Method method = type .getMethod ("from" , TemporalAccessor .class );
179
244
Object o = method .invoke (null , temporal );
@@ -184,7 +249,8 @@ private static <T extends TemporalAccessor> TemporalQuery<T> getTemporalQuery(Cl
184
249
throw new ConversionException ("could not create object of class " + type .getName (), e );
185
250
}
186
251
};
187
- } // endregion
252
+ }
253
+ // endregion
188
254
189
255
/**
190
256
* a DateFormatter to convert epoch milliseconds
0 commit comments