mirror of https://github.com/apache/lucene.git
LUCENE-2155: clear/initialize calendar fields in localized date tests
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@890407 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dcc66dfe2b
commit
2f7b7453b3
|
@ -121,6 +121,9 @@ Test Cases
|
||||||
index as well; improve javadocs of Filter to call out that the
|
index as well; improve javadocs of Filter to call out that the
|
||||||
provided reader is per-segment (Simon Willnauer via Mike McCandless)
|
provided reader is per-segment (Simon Willnauer via Mike McCandless)
|
||||||
|
|
||||||
|
* LUCENE-2155: Fix time and zone dependent localization test failures
|
||||||
|
in queryparser tests. (Uwe Schindler, Chris Male, Robert Muir)
|
||||||
|
|
||||||
======================= Release 3.0.0 2009-11-25 =======================
|
======================= Release 3.0.0 2009-11-25 =======================
|
||||||
|
|
||||||
Changes in backwards compatibility policy
|
Changes in backwards compatibility policy
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.lucene.misc;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
@ -60,7 +61,8 @@ public class ChainedFilterTest extends TestCase {
|
||||||
IndexWriter writer =
|
IndexWriter writer =
|
||||||
new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
|
new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
|
||||||
|
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = new GregorianCalendar();
|
||||||
|
cal.clear();
|
||||||
cal.setTimeInMillis(1041397200000L); // 2003 January 01
|
cal.setTimeInMillis(1041397200000L); // 2003 January 01
|
||||||
|
|
||||||
for (int i = 0; i < MAX; i++) {
|
for (int i = 0; i < MAX; i++) {
|
||||||
|
|
|
@ -392,7 +392,12 @@ public class TestPrecedenceQueryParser extends LocalizedTestCase {
|
||||||
public String getLocalizedDate(int year, int month, int day) {
|
public String getLocalizedDate(int year, int month, int day) {
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
Calendar calendar = new GregorianCalendar();
|
Calendar calendar = new GregorianCalendar();
|
||||||
|
calendar.clear();
|
||||||
calendar.set(year, month, day);
|
calendar.set(year, month, day);
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||||
|
calendar.set(Calendar.MINUTE, 59);
|
||||||
|
calendar.set(Calendar.SECOND, 59);
|
||||||
|
calendar.set(Calendar.MILLISECOND, 999);
|
||||||
return df.format(calendar.getTime());
|
return df.format(calendar.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -650,25 +650,24 @@ public class TestQPHelper extends LocalizedTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocalizedDate(int year, int month, int day,
|
private String getLocalizedDate(int year, int month, int day) {
|
||||||
boolean extendLastDate) {
|
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
Calendar calendar = new GregorianCalendar();
|
Calendar calendar = new GregorianCalendar();
|
||||||
|
calendar.clear();
|
||||||
calendar.set(year, month, day);
|
calendar.set(year, month, day);
|
||||||
if (extendLastDate) {
|
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||||
calendar.set(Calendar.MINUTE, 59);
|
calendar.set(Calendar.MINUTE, 59);
|
||||||
calendar.set(Calendar.SECOND, 59);
|
calendar.set(Calendar.SECOND, 59);
|
||||||
calendar.set(Calendar.MILLISECOND, 999);
|
calendar.set(Calendar.MILLISECOND, 999);
|
||||||
}
|
|
||||||
return df.format(calendar.getTime());
|
return df.format(calendar.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** for testing legacy DateField support */
|
/** for testing legacy DateField support */
|
||||||
public void testLegacyDateRange() throws Exception {
|
public void testLegacyDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4);
|
||||||
Calendar endDateExpected = new GregorianCalendar();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
|
endDateExpected.clear();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null, "["
|
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null, "["
|
||||||
|
@ -679,9 +678,10 @@ public class TestQPHelper extends LocalizedTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDateRange() throws Exception {
|
public void testDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4);
|
||||||
Calendar endDateExpected = new GregorianCalendar();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
|
endDateExpected.clear();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
final String defaultField = "default";
|
final String defaultField = "default";
|
||||||
|
|
|
@ -644,25 +644,24 @@ public class TestQueryParserWrapper extends LocalizedTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocalizedDate(int year, int month, int day,
|
private String getLocalizedDate(int year, int month, int day) {
|
||||||
boolean extendLastDate) {
|
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
Calendar calendar = new GregorianCalendar();
|
Calendar calendar = new GregorianCalendar();
|
||||||
|
calendar.clear();
|
||||||
calendar.set(year, month, day);
|
calendar.set(year, month, day);
|
||||||
if (extendLastDate) {
|
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||||
calendar.set(Calendar.MINUTE, 59);
|
calendar.set(Calendar.MINUTE, 59);
|
||||||
calendar.set(Calendar.SECOND, 59);
|
calendar.set(Calendar.SECOND, 59);
|
||||||
calendar.set(Calendar.MILLISECOND, 999);
|
calendar.set(Calendar.MILLISECOND, 999);
|
||||||
}
|
|
||||||
return df.format(calendar.getTime());
|
return df.format(calendar.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** for testing legacy DateField support */
|
/** for testing legacy DateField support */
|
||||||
public void testLegacyDateRange() throws Exception {
|
public void testLegacyDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4);
|
||||||
Calendar endDateExpected = new GregorianCalendar();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
|
endDateExpected.clear();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null, "["
|
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null, "["
|
||||||
|
@ -673,9 +672,10 @@ public class TestQueryParserWrapper extends LocalizedTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDateRange() throws Exception {
|
public void testDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4);
|
||||||
Calendar endDateExpected = new GregorianCalendar();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
|
endDateExpected.clear();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
final String defaultField = "default";
|
final String defaultField = "default";
|
||||||
|
|
|
@ -134,6 +134,7 @@ public class TestSearch extends LuceneTestCase {
|
||||||
|
|
||||||
static long Time(int year, int month, int day) {
|
static long Time(int year, int month, int day) {
|
||||||
GregorianCalendar calendar = new GregorianCalendar();
|
GregorianCalendar calendar = new GregorianCalendar();
|
||||||
|
calendar.clear();
|
||||||
calendar.set(year, month, day);
|
calendar.set(year, month, day);
|
||||||
return calendar.getTime().getTime();
|
return calendar.getTime().getTime();
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class TestDateTools extends LocalizedTestCase {
|
||||||
public void testStringtoTime() throws ParseException {
|
public void testStringtoTime() throws ParseException {
|
||||||
long time = DateTools.stringToTime("197001010000");
|
long time = DateTools.stringToTime("197001010000");
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar();
|
||||||
|
cal.clear();
|
||||||
cal.set(1970, 0, 1, // year=1970, month=january, day=1
|
cal.set(1970, 0, 1, // year=1970, month=january, day=1
|
||||||
0, 0, 0); // hour, minute, second
|
0, 0, 0); // hour, minute, second
|
||||||
cal.set(Calendar.MILLISECOND, 0);
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
|
@ -73,6 +74,7 @@ public class TestDateTools extends LocalizedTestCase {
|
||||||
|
|
||||||
public void testDateAndTimetoString() throws ParseException {
|
public void testDateAndTimetoString() throws ParseException {
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar();
|
||||||
|
cal.clear();
|
||||||
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
|
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
|
||||||
22, 8, 56); // hour, minute, second
|
22, 8, 56); // hour, minute, second
|
||||||
|
@ -137,6 +139,7 @@ public class TestDateTools extends LocalizedTestCase {
|
||||||
|
|
||||||
public void testRound() {
|
public void testRound() {
|
||||||
Calendar cal = new GregorianCalendar();
|
Calendar cal = new GregorianCalendar();
|
||||||
|
cal.clear();
|
||||||
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
|
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
|
||||||
22, 8, 56); // hour, minute, second
|
22, 8, 56); // hour, minute, second
|
||||||
|
|
|
@ -543,24 +543,24 @@ public class TestQueryParser extends LocalizedTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocalizedDate(int year, int month, int day, boolean extendLastDate) {
|
private String getLocalizedDate(int year, int month, int day) {
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
Calendar calendar = new GregorianCalendar();
|
Calendar calendar = new GregorianCalendar();
|
||||||
|
calendar.clear();
|
||||||
calendar.set(year, month, day);
|
calendar.set(year, month, day);
|
||||||
if (extendLastDate) {
|
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||||
calendar.set(Calendar.MINUTE, 59);
|
calendar.set(Calendar.MINUTE, 59);
|
||||||
calendar.set(Calendar.SECOND, 59);
|
calendar.set(Calendar.SECOND, 59);
|
||||||
calendar.set(Calendar.MILLISECOND, 999);
|
calendar.set(Calendar.MILLISECOND, 999);
|
||||||
}
|
|
||||||
return df.format(calendar.getTime());
|
return df.format(calendar.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** for testing legacy DateField support */
|
/** for testing legacy DateField support */
|
||||||
public void testLegacyDateRange() throws Exception {
|
public void testLegacyDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4);
|
||||||
Calendar endDateExpected = new GregorianCalendar();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
|
endDateExpected.clear();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null,
|
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null,
|
||||||
|
@ -570,9 +570,10 @@ public class TestQueryParser extends LocalizedTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDateRange() throws Exception {
|
public void testDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4);
|
||||||
Calendar endDateExpected = new GregorianCalendar();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
|
endDateExpected.clear();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
final String defaultField = "default";
|
final String defaultField = "default";
|
||||||
|
|
Loading…
Reference in New Issue