You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2016/04/07 22:29:34 UTC
[02/50] [abbrv] lucene-solr:apiv2: SOLR-8904: switch from
SimpleDateFormat to Instant.parse and format. [value] and ms() and
contrib/analytics now call DateMathParser to parse. DateFormatUtil is now
removed.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java b/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java
index e7de4d1..199423b 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java
@@ -17,6 +17,8 @@
package org.apache.solr.cloud;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -54,7 +56,7 @@ class SegmentTerminateEarlyTestState {
final Integer docKey = new Integer(numDocs);
SolrInputDocument doc = new SolrInputDocument();
doc.setField(keyField, ""+docKey);
- final int MM = TestMiniSolrCloudCluster.random().nextInt(60);
+ final int MM = TestMiniSolrCloudCluster.random().nextInt(60); // minutes
if (minTimestampMM == null || MM <= minTimestampMM.intValue()) {
if (minTimestampMM != null && MM < minTimestampMM.intValue()) {
minTimestampDocKeys.clear();
@@ -69,7 +71,7 @@ class SegmentTerminateEarlyTestState {
maxTimestampMM = new Integer(MM);
maxTimestampDocKeys.add(docKey);
}
- doc.setField(timestampField, "2016-01-01T00:"+MM+":00Z");
+ doc.setField(timestampField, ZonedDateTime.of(2016, 1, 1, 0, MM, 0, 0, ZoneOffset.UTC).toInstant().toString());
doc.setField(oddField, ""+(numDocs % 2));
doc.setField(quadField, ""+(numDocs % 4)+1);
cloudSolrClient.add(doc);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java
index 833cadd..dc7e0b0 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java
@@ -16,6 +16,16 @@
*/
package org.apache.solr.cloud;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
@@ -29,22 +39,11 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.params.StatsParams;
import org.apache.solr.common.util.NamedList;
-import org.apache.solr.util.DateFormatUtil;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import static org.apache.solr.common.params.FacetParams.FACET;
import static org.apache.solr.common.params.FacetParams.FACET_LIMIT;
import static org.apache.solr.common.params.FacetParams.FACET_MISSING;
@@ -474,7 +473,7 @@ public class TestCloudPivotFacet extends AbstractFullDistribZkTestBase {
// otherwise, build up a term filter...
String prefix = "{!term f=" + constraint.getField() + "}";
if (value instanceof Date) {
- return prefix + DateFormatUtil.formatExternal((Date)value);
+ return prefix + ((Date) value).toInstant();
} else {
return prefix + value;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLargeTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLargeTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLargeTest.java
index 176b57f..0fa4e8c 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLargeTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLargeTest.java
@@ -834,6 +834,7 @@ public class DistributedFacetPivotLargeTest extends BaseDistributedSearchTestCas
rfc = pf.getFacetRanges().get(0).getCounts();
for (RangeFacet.Count c : rfc) {
+
assertEquals(0, c.getCount()); // no docs in our ranges for this pivot drill down
}
@@ -927,7 +928,7 @@ public class DistributedFacetPivotLargeTest extends BaseDistributedSearchTestCas
addPivotDoc(oneShard, "id", getDocNum(), "place_s", "cardiff", "company_t", "microsoft polecat","pay_i",5824,"hiredate_dt", "2012-11-01T12:30:00Z");
addPivotDoc(oneShard, "id", getDocNum(), "place_s", "cardiff", "company_t", "microsoft ","pay_i",6539,"hiredate_dt", "2012-11-01T12:30:00Z");
addPivotDoc(oneShard, "id", getDocNum(), "place_s", "medical staffing network holdings, inc.", "company_t", "microsoft ","pay_i",6539,"hiredate_dt", "2012-11-01T12:30:00Z", "special_s", "xxx");
- addPivotDoc(oneShard, "id", getDocNum(), "place_s", "cardiff", "company_t", "polecat","pay_i",4352,"hiredate_dt", "2012-1-01T12:30:00Z", "special_s", "xxx");
+ addPivotDoc(oneShard, "id", getDocNum(), "place_s", "cardiff", "company_t", "polecat","pay_i",4352,"hiredate_dt", "2012-01-01T12:30:00Z", "special_s", "xxx");
addPivotDoc(oneShard, "id", getDocNum(), "place_s", "krakaw", "company_t", "polecat","pay_i",4352,"hiredate_dt", "2012-11-01T12:30:00Z", "special_s", SPECIAL);
addPivotDoc(twoShard, "id", getDocNum(), "place_s", "cardiff", "company_t", "microsoft","pay_i",12,"hiredate_dt", "2012-11-01T12:30:00Z", "special_s", SPECIAL);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java b/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java
index 3b99eb8..1bb860e 100644
--- a/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java
+++ b/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java
@@ -36,7 +36,6 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.SchemaField;
-import org.apache.solr.util.DateFormatUtil;
import org.apache.solr.util.TimeZoneUtils;
import org.junit.BeforeClass;
import org.junit.Ignore;
@@ -790,8 +789,8 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
//note: add_doc duplicates bday to bday_drf and a_tdt to a_drf (date range field)
add_doc(i, "201", f, "1976-07-04T12:08:56.235Z", ff, "1900-01-01T"+ooo);
add_doc(i, "202", f, "1976-07-05T00:00:00.000Z", ff, "1976-07-01T"+ooo);
- add_doc(i, "203", f, "1976-07-15T00:07:67.890Z", ff, "1976-07-04T"+ooo);
- add_doc(i, "204", f, "1976-07-21T00:07:67.890Z", ff, "1976-07-05T"+ooo);
+ add_doc(i, "203", f, "1976-07-15T00:07:57.890Z", ff, "1976-07-04T"+ooo);
+ add_doc(i, "204", f, "1976-07-21T00:07:57.890Z", ff, "1976-07-05T"+ooo);
add_doc(i, "205", f, "1976-07-13T12:12:25.255Z", ff, "1976-07-05T"+xxx);
add_doc(i, "206", f, "1976-07-03T17:01:23.456Z", ff, "1976-07-07T"+ooo);
add_doc(i, "207", f, "1976-07-12T12:12:25.255Z", ff, "1976-07-13T"+ooo);
@@ -3006,8 +3005,8 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
}
int gapNum = random().nextInt(100) + 1;
- params.add(FacetParams.FACET_RANGE_START, DateFormatUtil.formatExternal(dates[0]));
- params.add(FacetParams.FACET_RANGE_END, DateFormatUtil.formatExternal(dates[1]));
+ params.add(FacetParams.FACET_RANGE_START, dates[0].toInstant().toString());
+ params.add(FacetParams.FACET_RANGE_END, dates[1].toInstant().toString());
params.add(FacetParams.FACET_RANGE_GAP, String.format(Locale.ROOT, "+%d%s", gapNum, gapUnit));
addCommonRandomRangeParams(params);
params.add(FacetParams.FACET_RANGE, field);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
index c9b59d6..d10ea71 100644
--- a/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
+++ b/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
@@ -16,16 +16,18 @@
*/
package org.apache.solr.response;
+import java.io.StringWriter;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.Date;
+
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.util.DateUtil;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.SolrReturnFields;
-import org.junit.*;
-
-import java.io.StringWriter;
-import java.util.Arrays;
+import org.junit.BeforeClass;
+import org.junit.Test;
public class TestCSVResponseWriter extends SolrTestCaseJ4 {
@BeforeClass
@@ -123,7 +125,7 @@ public class TestCSVResponseWriter extends SolrTestCaseJ4 {
d.addField("foo_b",false);
d.addField("foo_f",1.414f);
d.addField("foo_d",-1.0E300);
- d.addField("foo_dt", DateUtil.parseDate("2000-01-02T03:04:05Z"));
+ d.addField("foo_dt", new Date(Instant.parse("2000-01-02T03:04:05Z").toEpochMilli()));
d.addField("score", "2.718");
d = new SolrDocument();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java b/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java
index 8b6ad1d..9e88b6e 100644
--- a/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java
@@ -18,24 +18,18 @@ package org.apache.solr.schema;
import java.io.File;
import java.nio.file.Paths;
-import java.text.ParseException;
import java.util.Collections;
import java.util.Date;
-import java.util.Locale;
import org.apache.lucene.index.IndexableField;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrResourceLoader;
-import org.apache.solr.util.DateFormatUtil;
-import org.apache.solr.util.DateMathParser;
-import org.junit.Ignore;
public class DateFieldTest extends SolrTestCaseJ4 {
private final String testInstanceDir = TEST_HOME() + File.separator + "collection1";
private final String testConfHome = testInstanceDir + File.separator + "conf"+ File.separator;
private TrieDateField f = null;
- private DateMathParser p = new DateMathParser(DateFormatUtil.UTC, Locale.ROOT);
@Override
public void setUp() throws Exception {
@@ -50,142 +44,20 @@ public class DateFieldTest extends SolrTestCaseJ4 {
f.init(schema, Collections.<String,String>emptyMap());
}
- public void assertFormatParsed(String expected, String input) throws ParseException {
- assertEquals("Input: " + input, expected, DateFormatUtil.formatDate(DateFormatUtil.parseMath(new Date(), input)));
- }
-
- public void assertFormatDate(String expected, long input) {
- assertEquals("Input: " + input, expected, DateFormatUtil.formatDate(new Date(input)));
- }
-
- public void testToInternal() throws Exception {
- assertFormatParsed("1995-12-31T23:59:59.999", "1995-12-31T23:59:59.999666Z");
- assertFormatParsed("1995-12-31T23:59:59.999", "1995-12-31T23:59:59.999Z");
- assertFormatParsed("1995-12-31T23:59:59.99", "1995-12-31T23:59:59.99Z");
- assertFormatParsed("1995-12-31T23:59:59.9", "1995-12-31T23:59:59.9Z");
- assertFormatParsed("1995-12-31T23:59:59", "1995-12-31T23:59:59Z");
-
- // here the input isn't in the canonical form, but we should be forgiving
- assertFormatParsed("1995-12-31T23:59:59.99", "1995-12-31T23:59:59.990Z");
- assertFormatParsed("1995-12-31T23:59:59.9", "1995-12-31T23:59:59.900Z");
- assertFormatParsed("1995-12-31T23:59:59.9", "1995-12-31T23:59:59.90Z");
- assertFormatParsed("1995-12-31T23:59:59", "1995-12-31T23:59:59.000Z");
- assertFormatParsed("1995-12-31T23:59:59", "1995-12-31T23:59:59.00Z");
- assertFormatParsed("1995-12-31T23:59:59", "1995-12-31T23:59:59.0Z");
-
- // kind of kludgy, but we have other tests for the actual date math
- assertFormatParsed(DateFormatUtil.formatDate(p.parseMath("/DAY")), "NOW/DAY");
-
- // as of Solr 1.3
- assertFormatParsed("1995-12-31T00:00:00", "1995-12-31T23:59:59Z/DAY");
- assertFormatParsed("1995-12-31T00:00:00", "1995-12-31T23:59:59.123Z/DAY");
- assertFormatParsed("1995-12-31T00:00:00", "1995-12-31T23:59:59.123999Z/DAY");
- }
-
- public void testToInternalObj() throws Exception {
- assertFormatDate("1995-12-31T23:59:59.999", 820454399999l);
- assertFormatDate("1995-12-31T23:59:59.99", 820454399990l);
- assertFormatDate("1995-12-31T23:59:59.9", 820454399900l);
- assertFormatDate("1995-12-31T23:59:59", 820454399000l);
- }
-
- public void assertParseMath(long expected, String input) {
- Date d = new Date(0);
- assertEquals("Input: "+input, expected, DateFormatUtil.parseMath(d, input).getTime());
- }
-
- // as of Solr1.3
- public void testParseMath() {
- assertParseMath(820454699999l, "1995-12-31T23:59:59.999765Z+5MINUTES");
- assertParseMath(820454699999l, "1995-12-31T23:59:59.999Z+5MINUTES");
- assertParseMath(820454699990l, "1995-12-31T23:59:59.99Z+5MINUTES");
- assertParseMath(194918400000l, "1976-03-06T03:06:00Z/DAY");
-
- // here the input isn't in the canonical form, but we should be forgiving
- assertParseMath(820454699990l, "1995-12-31T23:59:59.990Z+5MINUTES");
- assertParseMath(194918400000l, "1976-03-06T03:06:00.0Z/DAY");
- assertParseMath(194918400000l, "1976-03-06T03:06:00.00Z/DAY");
- assertParseMath(194918400000l, "1976-03-06T03:06:00.000Z/DAY");
- }
-
- public void testFormatter() {
- // just after epoch
- assertFormat("1970-01-01T00:00:00.005", 5L);
- assertFormat("1970-01-01T00:00:00", 0L);
- assertFormat("1970-01-01T00:00:00.37", 370L);
- assertFormat("1970-01-01T00:00:00.9", 900L);
-
- // well after epoch
- assertFormat("1999-12-31T23:59:59.005", 946684799005L);
- assertFormat("1999-12-31T23:59:59", 946684799000L);
- assertFormat("1999-12-31T23:59:59.37", 946684799370L);
- assertFormat("1999-12-31T23:59:59.9", 946684799900L);
-
- // waaaay after epoch
- assertFormat("12345-12-31T23:59:59.005", 327434918399005L);
- assertFormat("12345-12-31T23:59:59", 327434918399000L);
- assertFormat("12345-12-31T23:59:59.37", 327434918399370L);
- assertFormat("12345-12-31T23:59:59.9", 327434918399900L);
-
- // well before epoch
- assertFormat("0299-12-31T23:59:59", -52700112001000L);
- assertFormat("0299-12-31T23:59:59.123", -52700112000877L);
- assertFormat("0299-12-31T23:59:59.09", -52700112000910L);
-
- }
-
- /**
- * Using dates in the canonical format, verify that parsing+formating
- * is an identify function
- */
- public void testRoundTrip() throws Exception {
-
- // typical dates, various precision
- assertRoundTrip("1995-12-31T23:59:59.987Z");
- assertRoundTrip("1995-12-31T23:59:59.98Z");
- assertRoundTrip("1995-12-31T23:59:59.9Z");
- assertRoundTrip("1995-12-31T23:59:59Z");
- assertRoundTrip("1976-03-06T03:06:00Z");
-
- // dates with atypical years
- assertRoundTrip("0001-01-01T01:01:01Z");
- assertRoundTrip("12021-12-01T03:03:03Z");
- }
-
- @Ignore("SOLR-2773: Non-Positive years don't work")
- public void testRoundTripNonPositiveYear() throws Exception {
-
- // :TODO: ambiguity about year zero
- // assertRoundTrip("0000-04-04T04:04:04Z");
-
- // dates with negative years
- assertRoundTrip("-0005-05-05T05:05:05Z");
- assertRoundTrip("-2021-12-01T04:04:04Z");
- assertRoundTrip("-12021-12-01T02:02:02Z");
-
- // :TODO: assertFormat and assertToObject some negative years
-
- }
-
- protected void assertFormat(final String expected, final long millis) {
- assertEquals(expected, DateFormatUtil.formatDate(new Date(millis)));
- }
-
- protected void assertRoundTrip(String canonicalDate) throws Exception {
- Date d = DateFormatUtil.parseDate(canonicalDate);
- String result = DateFormatUtil.formatExternal(d);
- assertEquals("d:" + d.getTime(), canonicalDate, result);
-
- }
-
+ // NOTE: Many other tests were moved to DateMathParserTest
public void testCreateField() {
int props = FieldProperties.INDEXED ^ FieldProperties.STORED;
SchemaField sf = new SchemaField( "test", f, props, null );
+ // String
IndexableField out = f.createField(sf, "1995-12-31T23:59:59Z", 1.0f );
- assertEquals(820454399000l, f.toObject( out ).getTime() );
-
- out = f.createField(sf, new Date(820454399000l), 1.0f );
- assertEquals(820454399000l, f.toObject( out ).getTime() );
+ assertEquals(820454399000L, f.toObject( out ).getTime() );
+ // Date obj
+ out = f.createField(sf, new Date(820454399000L), 1.0f );
+ assertEquals(820454399000L, f.toObject( out ).getTime() );
+ // Date math
+ out = f.createField(sf, "1995-12-31T23:59:59.99Z+5MINUTES", 1.0f);
+ assertEquals(820454699990L, f.toObject( out ).getTime() );
}
+
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
index 73000b0..48a3f22 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
@@ -22,14 +22,12 @@ import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import java.io.File;
-
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
-import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -71,9 +69,9 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
private static final Pattern STORED_FIELD_NAME_PATTERN = Pattern.compile("_dv$");
static {
- START_RANDOM_EPOCH_MILLIS = LocalDateTime.of(1970, Month.JANUARY, 1, 0, 0)
+ START_RANDOM_EPOCH_MILLIS = LocalDateTime.of(-11000, Month.JANUARY, 1, 0, 0)// BC
.toInstant(ZoneOffset.UTC).toEpochMilli();
- END_RANDOM_EPOCH_MILLIS = LocalDateTime.of(2030, Month.DECEMBER, 31, 23, 59, 59, 999_000_000)
+ END_RANDOM_EPOCH_MILLIS = LocalDateTime.of(11000, Month.DECEMBER, 31, 23, 59, 59, 999_000_000) // AD, 5 digit year
.toInstant(ZoneOffset.UTC).toEpochMilli();
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
@@ -216,8 +214,7 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
}
case "date": {
long epochMillis = TestUtil.nextLong(random(), START_RANDOM_EPOCH_MILLIS, END_RANDOM_EPOCH_MILLIS);
- LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMillis), ZoneOffset.UTC);
- values[i] = dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + 'Z';
+ values[i] = Instant.ofEpochMilli(epochMillis).toString();
break;
}
default: throw new Exception("unknown type '" + valueType + "'");
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
index 09fa721..e1726f8 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
@@ -24,7 +24,7 @@ import com.google.common.collect.ImmutableMap;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.schema.TrieDateField;
-import org.apache.solr.util.DateFormatUtil;
+import org.apache.solr.util.DateMathParser;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
@@ -597,45 +597,45 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
doc = new SolrInputDocument();
doc.setField("id", "10001");
TrieDateField trieDF = new TrieDateField();
- Date tempDate = DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z");
- doc.setField("dateRemove", new Date[]{DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-07-02T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-03T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-03T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-04T12:00:00Z")
+ Date tempDate = DateMathParser.parseMath(null, "2014-02-01T12:00:00Z");
+ doc.setField("dateRemove", new Date[]{DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-07-02T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-03T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-03T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-04T12:00:00Z")
});
assertU(adoc(doc));
doc = new SolrInputDocument();
doc.setField("id", "10002");
- doc.setField("dateRemove", new Date[]{DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-07-02T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-02T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-03T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-04T12:00:00Z")
+ doc.setField("dateRemove", new Date[]{DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-07-02T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-02T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-03T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-04T12:00:00Z")
});
assertU(adoc(doc));
doc = new SolrInputDocument();
doc.setField("id", "10020");
- doc.setField("dateRemove", new Date[]{DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-03T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-04T12:00:00Z")
+ doc.setField("dateRemove", new Date[]{DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-03T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-04T12:00:00Z")
});
assertU(adoc(doc));
doc = new SolrInputDocument();
doc.setField("id", "10021");
- doc.setField("dateRemove", new Date[]{DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-02T12:00:00Z"),
- DateFormatUtil.parseMath(null, "2014-02-04T12:00:00Z")
+ doc.setField("dateRemove", new Date[]{DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-02T12:00:00Z"),
+ DateMathParser.parseMath(null, "2014-02-04T12:00:00Z")
});
assertU(adoc(doc));
assertU(commit());
assertQ(req("q", "dateRemove:*", "indent", "true"), "//result[@numFound = '4']");
- String dateString = DateFormatUtil.parseMath(null, "2014-02-02T12:00:00Z").toString();
+ String dateString = DateMathParser.parseMath(null, "2014-02-02T12:00:00Z").toString();
// assertQ(req("q", "dateRemove:"+URLEncoder.encode(dateString, "UTF-8"), "indent", "true"), "//result[@numFound = '3']");
// assertQ(req("q", "dateRemove:\"2014-09-02T12:00:00Z\"", "indent", "true"), "//result[@numFound = '3']");
// assertQ(req("q", "dateRemove:"+dateString, "indent", "true"), "//result[@numFound = '3']"); //Sun Feb 02 10:00:00 FNT 2014
@@ -645,8 +645,8 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
doc = new SolrInputDocument();
doc.setField("id", "10001");
List<Date> removeList = new ArrayList<Date>();
- removeList.add(DateFormatUtil.parseMath(null, "2014-09-02T12:00:00Z"));
- removeList.add(DateFormatUtil.parseMath(null, "2014-09-03T12:00:00Z"));
+ removeList.add(DateMathParser.parseMath(null, "2014-09-02T12:00:00Z"));
+ removeList.add(DateMathParser.parseMath(null, "2014-09-03T12:00:00Z"));
doc.setField("dateRemove", ImmutableMap.of("remove", removeList)); //behavior when hitting Solr through ZK
assertU(adoc(doc));
@@ -658,8 +658,8 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
doc = new SolrInputDocument();
doc.setField("id", "10021");
removeList = new ArrayList<Date>();
- removeList.add(DateFormatUtil.parseMath(null, "2014-09-02T12:00:00Z"));
- removeList.add(DateFormatUtil.parseMath(null, "2014-09-03T12:00:00Z"));
+ removeList.add(DateMathParser.parseMath(null, "2014-09-02T12:00:00Z"));
+ removeList.add(DateMathParser.parseMath(null, "2014-09-03T12:00:00Z"));
doc.setField("dateRemove", ImmutableMap.of("remove", removeList)); //behavior when hitting Solr through ZK
assertU(adoc(doc));
assertU(commit());
@@ -669,7 +669,7 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
doc = new SolrInputDocument();
doc.setField("id", "10001");
- doc.setField("dateRemove", ImmutableMap.of("remove", DateFormatUtil.parseMath(null, "2014-09-01T12:00:00Z"))); //behavior when hitting Solr directly
+ doc.setField("dateRemove", ImmutableMap.of("remove", DateMathParser.parseMath(null, "2014-09-01T12:00:00Z"))); //behavior when hitting Solr directly
assertU(adoc(doc));
assertU(commit());
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java b/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java
index c3623e8..726c71c 100644
--- a/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java
+++ b/solr/core/src/test/org/apache/solr/util/DateMathParserTest.java
@@ -16,20 +16,20 @@
*/
package org.apache.solr.util;
-import static org.apache.solr.util.DateFormatUtil.UTC;
-
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.solr.util.DateMathParser;
-
-import java.text.SimpleDateFormat;
import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
import java.util.Calendar;
import java.util.Date;
-import java.util.TimeZone;
+import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import java.util.HashMap;
-import java.text.ParseException;
+import java.util.TimeZone;
+
+import org.apache.lucene.util.LuceneTestCase;
+
+import static org.apache.solr.util.DateMathParser.UTC;
/**
* Tests that the functions in DateMathParser
@@ -333,6 +333,111 @@ public class DateMathParserTest extends LuceneTestCase {
}
}
-
+
+ /*
+ PARSING / FORMATTING (without date math) Formerly in DateFieldTest.
+ */
+
+
+ public void testFormatter() {
+ assertFormat("1995-12-31T23:59:59.999Z", 820454399999l);
+ assertFormat("1995-12-31T23:59:59.990Z", 820454399990l);
+ assertFormat("1995-12-31T23:59:59.900Z", 820454399900l);
+ assertFormat("1995-12-31T23:59:59Z", 820454399000l);
+
+ // just after epoch
+ assertFormat("1970-01-01T00:00:00.005Z", 5L);
+ assertFormat("1970-01-01T00:00:00Z", 0L);
+ assertFormat("1970-01-01T00:00:00.370Z", 370L);
+ assertFormat("1970-01-01T00:00:00.900Z", 900L);
+
+ // well after epoch
+ assertFormat("1999-12-31T23:59:59.005Z", 946684799005L);
+ assertFormat("1999-12-31T23:59:59Z", 946684799000L);
+ assertFormat("1999-12-31T23:59:59.370Z", 946684799370L);
+ assertFormat("1999-12-31T23:59:59.900Z", 946684799900L);
+
+ // waaaay after epoch ('+' is required for more than 4 digits in a year)
+ assertFormat("+12345-12-31T23:59:59.005Z", 327434918399005L);
+ assertFormat("+12345-12-31T23:59:59Z", 327434918399000L);
+ assertFormat("+12345-12-31T23:59:59.370Z", 327434918399370L);
+ assertFormat("+12345-12-31T23:59:59.900Z", 327434918399900L);
+
+ // well before epoch
+ assertFormat("0299-12-31T23:59:59Z", -52700112001000L);
+ assertFormat("0299-12-31T23:59:59.123Z", -52700112000877L);
+ assertFormat("0299-12-31T23:59:59.090Z", -52700112000910L);
+
+ // BC (negative years)
+ assertFormat("-12021-12-01T02:02:02Z", Instant.parse("-12021-12-01T02:02:02Z").toEpochMilli());
+ }
+
+ private void assertFormat(final String expected, final long millis) {
+ assertEquals(expected, Instant.ofEpochMilli(millis).toString());
+ }
+
+ /**
+ * Using dates in the canonical format, verify that parsing+formatting
+ * is an identify function
+ */
+ public void testRoundTrip() throws Exception {
+ // NOTE: the 2nd arg is what the round trip result looks like (may be null if same as input)
+
+ assertParseFormatEquals("1995-12-31T23:59:59.999666Z", "1995-12-31T23:59:59.999Z"); // beyond millis is truncated
+ assertParseFormatEquals("1995-12-31T23:59:59.999Z", "1995-12-31T23:59:59.999Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.99Z", "1995-12-31T23:59:59.990Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.9Z", "1995-12-31T23:59:59.900Z");
+ assertParseFormatEquals("1995-12-31T23:59:59Z", "1995-12-31T23:59:59Z");
+
+ // here the input isn't in the canonical form, but we should be forgiving
+ assertParseFormatEquals("1995-12-31T23:59:59.990Z", "1995-12-31T23:59:59.990Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.900Z", "1995-12-31T23:59:59.900Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.90Z", "1995-12-31T23:59:59.900Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.000Z", "1995-12-31T23:59:59Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.00Z", "1995-12-31T23:59:59Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.0Z", "1995-12-31T23:59:59Z");
+
+ // kind of kludgy, but we have other tests for the actual date math
+ //assertParseFormatEquals("NOW/DAY", p.parseMath("/DAY").toInstant().toString());
+
+ // as of Solr 1.3
+ assertParseFormatEquals("1995-12-31T23:59:59Z/DAY", "1995-12-31T00:00:00Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.123Z/DAY", "1995-12-31T00:00:00Z");
+ assertParseFormatEquals("1995-12-31T23:59:59.123999Z/DAY", "1995-12-31T00:00:00Z");
+
+ // typical dates, various precision (0,1,2,3 digits of millis)
+ assertParseFormatEquals("1995-12-31T23:59:59.987Z", null);
+ assertParseFormatEquals("1995-12-31T23:59:59.98Z", "1995-12-31T23:59:59.980Z");//add 0 ms
+ assertParseFormatEquals("1995-12-31T23:59:59.9Z", "1995-12-31T23:59:59.900Z");//add 00 ms
+ assertParseFormatEquals("1995-12-31T23:59:59Z", null);
+ assertParseFormatEquals("1976-03-06T03:06:00Z", null);
+ assertParseFormatEquals("1995-12-31T23:59:59.987654Z", "1995-12-31T23:59:59.987Z");//truncate nanoseconds off
+
+ // dates with atypical years
+ assertParseFormatEquals("0001-01-01T01:01:01Z", null);
+ assertParseFormatEquals("+12021-12-01T03:03:03Z", null);
+
+ assertParseFormatEquals("0000-04-04T04:04:04Z", null); // note: 0 AD is also known as 1 BC
+
+ // dates with negative years (BC)
+ assertParseFormatEquals("-0005-05-05T05:05:05Z", null);
+ assertParseFormatEquals("-2021-12-01T04:04:04Z", null);
+ assertParseFormatEquals("-12021-12-01T02:02:02Z", null);
+ }
+
+ public void testParseLenient() throws Exception {
+ // dates that only parse thanks to lenient mode of DateTimeFormatter
+ assertParseFormatEquals("10995-12-31T23:59:59.990Z", "+10995-12-31T23:59:59.990Z"); // missing '+' 5 digit year
+ assertParseFormatEquals("995-1-2T3:4:5Z", "0995-01-02T03:04:05Z"); // wasn't 0 padded
+ }
+
+ private void assertParseFormatEquals(String inputStr, String expectedStr) {
+ if (expectedStr == null) {
+ expectedStr = inputStr;
+ }
+ Date inputDate = DateMathParser.parseMath(null, inputStr);
+ String resultStr = inputDate.toInstant().toString();
+ assertEquals("d:" + inputDate.getTime(), expectedStr, resultStr);
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java
index d41673d..be70210 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java
@@ -16,14 +16,6 @@
*/
package org.apache.solr.client.solrj;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.FacetParams;
-import org.apache.solr.common.params.HighlightParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.params.StatsParams;
-import org.apache.solr.common.params.TermsParams;
-import org.apache.solr.common.util.DateUtil;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@@ -31,6 +23,13 @@ import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.FacetParams;
+import org.apache.solr.common.params.HighlightParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.StatsParams;
+import org.apache.solr.common.params.TermsParams;
+
/**
* This is an augmented SolrParams with get/set/add fields for common fields used
@@ -266,9 +265,9 @@ public class SolrQuery extends ModifiableSolrParams
*/
public SolrQuery addDateRangeFacet(String field, Date start, Date end, String gap) {
add(FacetParams.FACET_RANGE, field);
- add(String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_START), DateUtil.getThreadLocalDateFormat().format(start));
- add(String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_END), DateUtil.getThreadLocalDateFormat().format(end));
- add(String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_GAP), gap);
+ add(String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_START), start.toInstant().toString());
+ add(String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_END), end.toInstant().toString());
+ add(String.format(Locale.ROOT, "f.%s.%s", field, FacetParams.FACET_RANGE_GAP), gap);
this.set(FacetParams.FACET, true);
return this;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
index e794dab..272335a 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
@@ -16,31 +16,30 @@
*/
package org.apache.solr.client.solrj.impl;
-import org.apache.solr.client.solrj.ResponseParser;
-import org.apache.solr.common.SolrDocument;
-import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.util.DateUtil;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.common.util.XMLErrorLogger;
-import org.apache.solr.common.EmptyEntityResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-
import java.io.InputStream;
import java.io.Reader;
import java.lang.invoke.MethodHandles;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
+import org.apache.solr.client.solrj.ResponseParser;
+import org.apache.solr.common.EmptyEntityResolver;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.common.util.XMLErrorLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
*
*
@@ -173,7 +172,7 @@ public class XMLResponseParser extends ResponseParser
@Override
public Date read( String txt ) {
try {
- return DateUtil.parseDate(txt);
+ return new Date(Instant.parse(txt).toEpochMilli());
}
catch( Exception ex ) {
ex.printStackTrace();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java b/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
index 31d54a8..beed40e 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
@@ -16,16 +16,6 @@
*/
package org.apache.solr.client.solrj.util;
-import org.apache.solr.common.SolrDocument;
-import org.apache.solr.common.SolrInputDocument;
-import org.apache.solr.common.SolrInputField;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.util.Base64;
-import org.apache.solr.common.util.ContentStream;
-import org.apache.solr.common.util.ContentStreamBase;
-import org.apache.solr.common.util.DateUtil;
-import org.apache.solr.common.util.XML;
-
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
@@ -36,6 +26,14 @@ import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.SolrInputField;
+import org.apache.solr.common.cloud.Slice;
+import org.apache.solr.common.util.Base64;
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.ContentStreamBase;
+import org.apache.solr.common.util.XML;
+
/**
*
@@ -111,7 +109,7 @@ public class ClientUtils
private static void writeVal(Writer writer, float boost, String name, Object v, String update) throws IOException {
if (v instanceof Date) {
- v = DateUtil.getThreadLocalDateFormat().format( (Date)v );
+ v = ((Date)v).toInstant().toString();
} else if (v instanceof byte[]) {
byte[] bytes = (byte[]) v;
v = Base64.byteArrayToBase64(bytes, 0, bytes.length);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/solrj/src/java/org/apache/solr/common/util/DateUtil.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/DateUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/DateUtil.java
deleted file mode 100644
index 9bf7a2b..0000000
--- a/solr/solrj/src/java/org/apache/solr/common/util/DateUtil.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.common.util;
-import java.io.IOException;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.TimeZone;
-
-
-/**
- * This class has some code from HttpClient DateUtil.
- */
-public class DateUtil {
- //start HttpClient
- /**
- * Date format pattern used to parse HTTP date headers in RFC 1123 format.
- */
- public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";
-
- /**
- * Date format pattern used to parse HTTP date headers in RFC 1036 format.
- */
- public static final String PATTERN_RFC1036 = "EEEE, dd-MMM-yy HH:mm:ss zzz";
-
- /**
- * Date format pattern used to parse HTTP date headers in ANSI C
- * <code>asctime()</code> format.
- */
- public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
- //These are included for back compat
- private static final Collection<String> DEFAULT_HTTP_CLIENT_PATTERNS = Arrays.asList(
- PATTERN_ASCTIME, PATTERN_RFC1036, PATTERN_RFC1123);
-
- private static final Date DEFAULT_TWO_DIGIT_YEAR_START;
-
- static {
- Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ROOT);
- calendar.set(2000, Calendar.JANUARY, 1, 0, 0);
- DEFAULT_TWO_DIGIT_YEAR_START = calendar.getTime();
- }
-
- private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
-
- //end HttpClient
-
- //---------------------------------------------------------------------------------------
-
- /**
- * A suite of default date formats that can be parsed, and thus transformed to the Solr specific format
- */
- public static final Collection<String> DEFAULT_DATE_FORMATS = new ArrayList<>();
-
- static {
- DEFAULT_DATE_FORMATS.add("yyyy-MM-dd'T'HH:mm:ss'Z'");
- DEFAULT_DATE_FORMATS.add("yyyy-MM-dd'T'HH:mm:ss");
- DEFAULT_DATE_FORMATS.add("yyyy-MM-dd");
- DEFAULT_DATE_FORMATS.add("yyyy-MM-dd hh:mm:ss");
- DEFAULT_DATE_FORMATS.add("yyyy-MM-dd HH:mm:ss");
- DEFAULT_DATE_FORMATS.add("EEE MMM d hh:mm:ss z yyyy");
- DEFAULT_DATE_FORMATS.addAll(DEFAULT_HTTP_CLIENT_PATTERNS);
- }
-
- /**
- * Returns a formatter that can be use by the current thread if needed to
- * convert Date objects to the Internal representation.
- *
- * @param d The input date to parse
- * @return The parsed {@link java.util.Date}
- * @throws java.text.ParseException If the input can't be parsed
- */
- public static Date parseDate(String d) throws ParseException {
- return parseDate(d, DEFAULT_DATE_FORMATS);
- }
-
- public static Date parseDate(String d, Collection<String> fmts) throws ParseException {
- // 2007-04-26T08:05:04Z
- if (d.endsWith("Z") && d.length() > 20) {
- return getThreadLocalDateFormat().parse(d);
- }
- return parseDate(d, fmts, null);
- }
-
- /**
- * Slightly modified from org.apache.commons.httpclient.util.DateUtil.parseDate
- * <p>
- * Parses the date value using the given date formats.
- *
- * @param dateValue the date value to parse
- * @param dateFormats the date formats to use
- * @param startDate During parsing, two digit years will be placed in the range
- * <code>startDate</code> to <code>startDate + 100 years</code>. This value may
- * be <code>null</code>. When <code>null</code> is given as a parameter, year
- * <code>2000</code> will be used.
- * @return the parsed date
- * @throws ParseException if none of the dataFormats could parse the dateValue
- */
- public static Date parseDate(
- String dateValue,
- Collection<String> dateFormats,
- Date startDate
- ) throws ParseException {
-
- if (dateValue == null) {
- throw new IllegalArgumentException("dateValue is null");
- }
- if (dateFormats == null) {
- dateFormats = DEFAULT_HTTP_CLIENT_PATTERNS;
- }
- if (startDate == null) {
- startDate = DEFAULT_TWO_DIGIT_YEAR_START;
- }
- // trim single quotes around date if present
- // see issue #5279
- if (dateValue.length() > 1
- && dateValue.startsWith("'")
- && dateValue.endsWith("'")
- ) {
- dateValue = dateValue.substring(1, dateValue.length() - 1);
- }
-
- SimpleDateFormat dateParser = null;
- Iterator formatIter = dateFormats.iterator();
-
- while (formatIter.hasNext()) {
- String format = (String) formatIter.next();
- if (dateParser == null) {
- dateParser = new SimpleDateFormat(format, Locale.ENGLISH);
- dateParser.setTimeZone(GMT);
- dateParser.set2DigitYearStart(startDate);
- } else {
- dateParser.applyPattern(format);
- }
- try {
- return dateParser.parse(dateValue);
- } catch (ParseException pe) {
- // ignore this exception, we will try the next format
- }
- }
-
- // we were unable to parse the date
- throw new ParseException("Unable to parse the date " + dateValue, 0);
- }
-
-
- /**
- * Returns a formatter that can be use by the current thread if needed to
- * convert Date objects to the Internal representation.
- *
- * @return The {@link java.text.DateFormat} for the current thread
- */
- public static DateFormat getThreadLocalDateFormat() {
- return fmtThreadLocal.get();
- }
-
- public static TimeZone UTC = TimeZone.getTimeZone("UTC");
- private static ThreadLocalDateFormat fmtThreadLocal = new ThreadLocalDateFormat();
-
- private static class ThreadLocalDateFormat extends ThreadLocal<DateFormat> {
- DateFormat proto;
-
- public ThreadLocalDateFormat() {
- super();
- //2007-04-26T08:05:04Z
- SimpleDateFormat tmp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ROOT);
- tmp.setTimeZone(UTC);
- proto = tmp;
- }
-
- @Override
- protected DateFormat initialValue() {
- return (DateFormat) proto.clone();
- }
- }
-
- /** Formats the date and returns the calendar instance that was used (which may be reused) */
- public static Calendar formatDate(Date date, Calendar cal, Appendable out) throws IOException {
- // using a stringBuilder for numbers can be nice since
- // a temporary string isn't used (it's added directly to the
- // builder's buffer.
-
- StringBuilder sb = out instanceof StringBuilder ? (StringBuilder)out : new StringBuilder();
- if (cal==null) cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ROOT);
- cal.setTime(date);
-
- int i = cal.get(Calendar.YEAR);
- sb.append(i);
- sb.append('-');
- i = cal.get(Calendar.MONTH) + 1; // 0 based, so add 1
- if (i<10) sb.append('0');
- sb.append(i);
- sb.append('-');
- i=cal.get(Calendar.DAY_OF_MONTH);
- if (i<10) sb.append('0');
- sb.append(i);
- sb.append('T');
- i=cal.get(Calendar.HOUR_OF_DAY); // 24 hour time format
- if (i<10) sb.append('0');
- sb.append(i);
- sb.append(':');
- i=cal.get(Calendar.MINUTE);
- if (i<10) sb.append('0');
- sb.append(i);
- sb.append(':');
- i=cal.get(Calendar.SECOND);
- if (i<10) sb.append('0');
- sb.append(i);
- i=cal.get(Calendar.MILLISECOND);
- if (i != 0) {
- sb.append('.');
- if (i<100) sb.append('0');
- if (i<10) sb.append('0');
- sb.append(i);
-
- // handle canonical format specifying fractional
- // seconds shall not end in '0'. Given the slowness of
- // integer div/mod, simply checking the last character
- // is probably the fastest way to check.
- int lastIdx = sb.length()-1;
- if (sb.charAt(lastIdx)=='0') {
- lastIdx--;
- if (sb.charAt(lastIdx)=='0') {
- lastIdx--;
- }
- sb.setLength(lastIdx+1);
- }
-
- }
- sb.append('Z');
-
- if (out != sb)
- out.append(sb);
-
- return cal;
- }
-
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/solrj/src/test/org/apache/solr/client/solrj/SolrQueryTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrQueryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrQueryTest.java
index 43fdff4..816a2cc 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrQueryTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrQueryTest.java
@@ -16,14 +16,6 @@
*/
package org.apache.solr.client.solrj;
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.solr.client.solrj.SolrQuery.SortClause;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.FacetParams;
-
-import junit.framework.Assert;
-import org.apache.solr.common.util.DateUtil;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
@@ -33,6 +25,12 @@ import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
+import junit.framework.Assert;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.SolrQuery.SortClause;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.FacetParams;
+
/**
*
*
@@ -301,8 +299,8 @@ public class SolrQueryTest extends LuceneTestCase {
q.addDateRangeFacet("field", start, end, "+1MONTH");
assertEquals("true", q.get(FacetParams.FACET));
assertEquals("field", q.get(FacetParams.FACET_RANGE));
- assertEquals(DateUtil.getThreadLocalDateFormat().format(start), q.get("f.field." + FacetParams.FACET_RANGE_START));
- assertEquals(DateUtil.getThreadLocalDateFormat().format(end), q.get("f.field." + FacetParams.FACET_RANGE_END));
+ assertEquals(start.toInstant().toString(), q.get("f.field." + FacetParams.FACET_RANGE_START));
+ assertEquals(end.toInstant().toString(), q.get("f.field." + FacetParams.FACET_RANGE_END));
assertEquals("+1MONTH", q.get("f.field." + FacetParams.FACET_RANGE_GAP));
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
index 1eea454..7a69815 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
@@ -20,6 +20,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.Date;
import java.util.List;
import junit.framework.Assert;
@@ -27,7 +29,6 @@ import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestRuleLimitSysouts.Limit;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.util.DateUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrResourceLoader;
import org.junit.Test;
@@ -82,8 +83,8 @@ public class QueryResponseTest extends LuceneTestCase {
assertEquals("4.0", price.getCounts().get(4).getValue());
assertEquals(0, price.getCounts().get(4).getCount());
- assertEquals(DateUtil.parseDate("2005-02-13T15:26:37Z"), manufacturedateDt.getStart());
- assertEquals(DateUtil.parseDate("2008-02-13T15:26:37Z"), manufacturedateDt.getEnd());
+ assertEquals(new Date(Instant.parse("2005-02-13T15:26:37Z").toEpochMilli()), manufacturedateDt.getStart());
+ assertEquals(new Date(Instant.parse("2008-02-13T15:26:37Z").toEpochMilli()), manufacturedateDt.getEnd());
assertEquals("+1YEAR", manufacturedateDt.getGap());
assertEquals("2005-02-13T15:26:37Z", manufacturedateDt.getCounts().get(0).getValue());
assertEquals(4, manufacturedateDt.getCounts().get(0).getCount());
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
index 812663e..a751459 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -16,8 +16,31 @@
*/
package org.apache.solr;
-import junit.framework.Assert;
+import javax.servlet.Filter;
+import java.io.File;
+import java.io.IOException;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Random;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.TestUtil;
@@ -26,7 +49,6 @@ import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettyConfig;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
@@ -37,7 +59,6 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
-import org.apache.solr.util.DateFormatUtil;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -48,31 +69,6 @@ import org.junit.runners.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.servlet.Filter;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.lang.invoke.MethodHandles;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Random;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.concurrent.atomic.AtomicInteger;
-
/**
* Helper base class for distributed search test cases
*
@@ -1086,7 +1082,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
public Object val() {
long v = r.nextLong();
Date d = new Date(v);
- return DateFormatUtil.formatExternal(d);
+ return d.toInstant().toString();
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/94c04237/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
----------------------------------------------------------------------
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index 6e511d7..3ce252f 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -37,7 +37,18 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.*;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
import java.util.logging.Level;
import com.carrotsearch.randomizedtesting.RandomizedContext;
@@ -86,7 +97,6 @@ import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.util.AbstractSolrTestCase;
-import org.apache.solr.util.DateFormatUtil;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.RevertDefaultThreadHandlerRule;
import org.apache.solr.util.SSLTestConfig;
@@ -2036,7 +2046,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
* @see #randomSkewedDate
*/
public static String randomDate() {
- return DateFormatUtil.formatExternal(new Date(random().nextLong()));
+ return Instant.ofEpochMilli(random().nextLong()).toString();
}
/**