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@7a1bf3767c91d1e643e7b34519e5ef97962390d7
*/
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();
}
}
