Github user barrotsteindev commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/435#discussion_r209430852
--- Diff:
solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java
---
@@ -896,13 +899,125 @@ public void testCascadingParsers() throws Exception {
assertTrue(mixedDates.isEmpty());
}
- private Date parse(DateTimeFormatter dateTimeFormatter, String
dateString) {
+ // TestsExtractionDateUtil that mimic TestExtractionDateUtil
+ public void testISO8601() throws IOException {
+ // dates with atypical years
+ // This test tries to mimic TestExtractionDateUtil#testISO8601
+
+ String[] dateStrings = {
+ "0001-01-01T01:01:01Z", "+12021-12-01T03:03:03Z",
+ "0000-04-04T04:04:04Z", "-0005-05-05T05:05:05Z",
+ "-2021-12-01T04:04:04Z", "-12021-12-01T02:02:02Z"
+ };
+
+ int id = 1;
+
+ // ensure strings are parsed
+ for(String notInFormatDateString: dateStrings) {
+ IndexSchema schema = h.getCore().getLatestSchema();
+ assertNotNull(schema.getFieldOrNull("date_dt")); // should match
"*_dt" dynamic field
+ SolrInputDocument d =
processAdd("parse-date-extraction-util-formats", doc(f("id", id), f("date_dt",
notInFormatDateString)));
+ assertNotNull(d);
+ assertTrue("Date string: " + notInFormatDateString + " was not
parsed as a date", d.getFieldValue("date_dt") instanceof Date);
+ assertEquals(notInFormatDateString, ((Date)
d.getField("date_dt").getFirstValue()).toInstant().toString());
+ assertU(commit());
+ assertQ(req("id:" + id), "//date[@name='date_dt'][.='" +
notInFormatDateString + "']");
+ ++id;
+ }
+
+ // odd values are date strings, even values are expected strings
+ String[] lenientDateStrings = {
+ "10995-12-31T23:59:59.990Z", "+10995-12-31T23:59:59.990Z",
+ "995-1-2T3:4:5Z", "0995-01-02T03:04:05Z",
+ "2021-01-01t03:04:05", "2021-01-01T03:04:05Z",
+ "2021-12-01 04:04:04", "2021-12-01T04:04:04Z"
+ };
+
+ // ensure sure strings that should be parsed using lenient resolver
are properly parsed
+ for(int i = 0; i < lenientDateStrings.length; ++i) {
+ String lenientDateString = lenientDateStrings[i];
+ String expectedString = lenientDateStrings[++i];
+ IndexSchema schema = h.getCore().getLatestSchema();
+ assertNotNull(schema.getFieldOrNull("date_dt")); // should match
"*_dt" dynamic field
+ SolrInputDocument d =
processAdd("parse-date-extraction-util-formats", doc(f("id", id), f("date_dt",
lenientDateString)));
+ assertNotNull(d);
+ assertTrue("Date string: " + lenientDateString + " was not parsed as
a date",
+ d.getFieldValue("date_dt") instanceof Date);
+ assertEquals(expectedString, ((Date)
d.getField("date_dt").getFirstValue()).toInstant().toString());
+ ++id;
+ }
+ }
+
+ // this test has had problems when the JDK timezone is
Americas/Metlakatla
+ public void testAKSTZone() throws IOException {
+ final String inputString = "Thu Nov 13 04:35:51 AKST 2008";
+
+ final long expectTs = 1226583351000L;
+ assertEquals(expectTs,
+ DateTimeFormatter.ofPattern("EEE MMM d HH:mm:ss z yyyy",
Locale.ENGLISH)
+ .withZone(ZoneId.of("UTC")).parse(inputString,
Instant::from).toEpochMilli());
+
+ assertParsedDate(inputString,
Date.from(Instant.ofEpochMilli(expectTs)),
"parse-date-extraction-util-formats");
+ }
+
+ public void testNoTime() throws IOException {
+ Instant instant = instant(2005, 10, 7, 0, 0, 0);
+ String inputString = "2005-10-07";
+ assertParsedDate(inputString, Date.from(instant),
"parse-date-extraction-util-formats");
+ }
+
+ public void testRfc1123() throws IOException {
+ assertParsedDate("Fri, 07 Oct 2005 13:14:15 GMT",
Date.from(inst20051007131415()), "parse-date-extraction-util-formats");
+ }
+
+ public void testRfc1036() throws IOException {
+ assertParsedDate("Friday, 07-Oct-05 13:14:15 GMT",
Date.from(inst20051007131415()), "parse-date-extraction-util-formats");
+ }
+
+ @AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-12593")
--- End diff --
This seems to pass as is, although I am still hesitant, perhaps I missed
something?
Would be nice if another set of eyes looked at this one.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]