Github user dsmiley commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/428#discussion_r207725540
--- 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 --
I worked on test program demonstrating the JDK issue and I see now that
this has already been reported:
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8177021 (we should put
a comment about this in the code). It's nice to see it has been fixed in JDK 9
(and my test program revealed that too).
During my exploration of this, I discovered that a lowercase 'z' in the
pattern can parse various formats, and so can "VV". I replaced the 5-'Z'
patterns in the test file with a single lower 'z' and the tests passed. FYI
this part of the javadocs is helpful:
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatterBuilder.html#appendPattern-java.lang.String-
(builder has more detail than the DateTimeFormatter).
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]