Github user dsmiley commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/428#discussion_r207700607
--- Diff:
solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.java
---
@@ -172,4 +181,34 @@ public void init(NamedList args) {
return (null == type) || type instanceof DateValueFieldType;
};
}
+
+ public static void validateFormatter(DateTimeFormatter formatter) {
+ // check it's valid via round-trip
+ try {
+ parseInstant(formatter, formatter.format(Instant.now()));
+ } catch (Exception e) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Bad or unsupported pattern: " +
formatter.toFormat().toString(), e);
+ }
+ }
+
+ private static Instant parseInstant(DateTimeFormatter formatter, String
dateStr) {
+ final TemporalAccessor temporalAccessor = formatter.parse(dateStr);
+ // parsed successfully. But is it a full instant or just to the day?
+ if (temporalAccessor.isSupported(ChronoField.INSTANT_SECONDS)) { //
has time
+ // has offset time
+ if(temporalAccessor.isSupported(ChronoField.OFFSET_SECONDS)) {
--- End diff --
This part, checking OFFSET_SECONDS ought not to be present here, I think.
INSTANT_SECONDS should be self-sufficient. See
java.time.Parsed.resolveInstant() which gives clues as to what's going on. The
override "zone" we set earlier on the formatter is taking precedence over the
OFFSET_SECONDS, leading you to try this as a work-around. I wonder if this is
a JDK bug; IMO it ought to be flipped.
I think we may need to be smarter about when to set the default zone on the
formatter and when not to. If the format specifies the zone or has a 'Z'
literal, then I think we don't; otherwise we set it. Or we don't set it at all
there and incorporate it here in parseInstant() which may be safer. I'll
propose something more concrete after I get some sleep; I have some WIP code.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]