Allow use of LocalDateTime#atZone() in DateTimeFormatterTimestampConverter (elastic/x-pack-elasticsearch#3811)
Adds a `@SuppressForbidden` annotation to permit use of a trappy method from `java.time`, pending resolution of elastic/x-pack-elasticsearch#3810. X-pack component of elasticsearch#28476. Original commit: elastic/x-pack-elasticsearch@c5e1ae0970
This commit is contained in:
parent
ee834026d1
commit
a1cb0911d3
|
@ -5,6 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.core.ml.utils.time;
|
||||
|
||||
import org.elasticsearch.cli.SuppressForbidden;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
@ -84,6 +86,11 @@ public class DateTimeFormatterTimestampConverter implements TimestampConverter {
|
|||
if (hasTimeZone) {
|
||||
return Instant.from(parsed);
|
||||
}
|
||||
return toInstantUnsafelyIgnoringAmbiguity(parsed);
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "TODO https://github.com/elastic/x-pack-elasticsearch/issues/3810")
|
||||
private Instant toInstantUnsafelyIgnoringAmbiguity(TemporalAccessor parsed) {
|
||||
return LocalDateTime.from(parsed).atZone(defaultZoneId).toInstant();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue