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:
David Turner 2018-02-01 14:33:23 +00:00 committed by GitHub
parent ee834026d1
commit a1cb0911d3
1 changed files with 7 additions and 0 deletions

View File

@ -5,6 +5,8 @@
*/ */
package org.elasticsearch.xpack.core.ml.utils.time; package org.elasticsearch.xpack.core.ml.utils.time;
import org.elasticsearch.cli.SuppressForbidden;
import java.time.DateTimeException; import java.time.DateTimeException;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
@ -84,6 +86,11 @@ public class DateTimeFormatterTimestampConverter implements TimestampConverter {
if (hasTimeZone) { if (hasTimeZone) {
return Instant.from(parsed); 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(); return LocalDateTime.from(parsed).atZone(defaultZoneId).toInstant();
} }
} }