diff --git a/CHANGES.txt b/CHANGES.txt index 04f62fc759f..c2a4851294b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -121,6 +121,9 @@ Test Cases index as well; improve javadocs of Filter to call out that the 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 ======================= Changes in backwards compatibility policy diff --git a/contrib/misc/src/test/org/apache/lucene/misc/ChainedFilterTest.java b/contrib/misc/src/test/org/apache/lucene/misc/ChainedFilterTest.java index 2ff0cef54ff..0c794a47655 100644 --- a/contrib/misc/src/test/org/apache/lucene/misc/ChainedFilterTest.java +++ b/contrib/misc/src/test/org/apache/lucene/misc/ChainedFilterTest.java @@ -18,6 +18,7 @@ package org.apache.lucene.misc; */ import java.util.Calendar; +import java.util.GregorianCalendar; import junit.framework.TestCase; @@ -60,7 +61,8 @@ public class ChainedFilterTest extends TestCase { IndexWriter writer = 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 for (int i = 0; i < MAX; i++) { diff --git a/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java b/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java index e16a80aea0f..63c7ae37082 100644 --- a/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java +++ b/contrib/misc/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java @@ -392,7 +392,12 @@ public class TestPrecedenceQueryParser extends LocalizedTestCase { public String getLocalizedDate(int year, int month, int day) { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); Calendar calendar = new GregorianCalendar(); + calendar.clear(); 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()); } diff --git a/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java b/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java index 36d368a55fb..c9b44a2535d 100644 --- a/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java +++ b/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java @@ -650,25 +650,24 @@ public class TestQPHelper 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); Calendar calendar = new GregorianCalendar(); + calendar.clear(); calendar.set(year, month, day); - if (extendLastDate) { - calendar.set(Calendar.HOUR_OF_DAY, 23); - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - calendar.set(Calendar.MILLISECOND, 999); - } + 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()); } /** for testing legacy DateField support */ public void testLegacyDateRange() throws Exception { - String startDate = getLocalizedDate(2002, 1, 1, false); - String endDate = getLocalizedDate(2002, 1, 4, false); + String startDate = getLocalizedDate(2002, 1, 1); + String endDate = getLocalizedDate(2002, 1, 4); Calendar endDateExpected = new GregorianCalendar(); + endDateExpected.clear(); endDateExpected.set(2002, 1, 4, 23, 59, 59); endDateExpected.set(Calendar.MILLISECOND, 999); assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null, "[" @@ -679,9 +678,10 @@ public class TestQPHelper extends LocalizedTestCase { } public void testDateRange() throws Exception { - String startDate = getLocalizedDate(2002, 1, 1, false); - String endDate = getLocalizedDate(2002, 1, 4, false); + String startDate = getLocalizedDate(2002, 1, 1); + String endDate = getLocalizedDate(2002, 1, 4); Calendar endDateExpected = new GregorianCalendar(); + endDateExpected.clear(); endDateExpected.set(2002, 1, 4, 23, 59, 59); endDateExpected.set(Calendar.MILLISECOND, 999); final String defaultField = "default"; diff --git a/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java b/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java index 9f4fe82bf62..9d0f07c7b7b 100644 --- a/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java +++ b/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java @@ -644,25 +644,24 @@ public class TestQueryParserWrapper 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); Calendar calendar = new GregorianCalendar(); + calendar.clear(); calendar.set(year, month, day); - if (extendLastDate) { - calendar.set(Calendar.HOUR_OF_DAY, 23); - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - calendar.set(Calendar.MILLISECOND, 999); - } + 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()); } /** for testing legacy DateField support */ public void testLegacyDateRange() throws Exception { - String startDate = getLocalizedDate(2002, 1, 1, false); - String endDate = getLocalizedDate(2002, 1, 4, false); + String startDate = getLocalizedDate(2002, 1, 1); + String endDate = getLocalizedDate(2002, 1, 4); Calendar endDateExpected = new GregorianCalendar(); + endDateExpected.clear(); endDateExpected.set(2002, 1, 4, 23, 59, 59); endDateExpected.set(Calendar.MILLISECOND, 999); assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null, "[" @@ -673,9 +672,10 @@ public class TestQueryParserWrapper extends LocalizedTestCase { } public void testDateRange() throws Exception { - String startDate = getLocalizedDate(2002, 1, 1, false); - String endDate = getLocalizedDate(2002, 1, 4, false); + String startDate = getLocalizedDate(2002, 1, 1); + String endDate = getLocalizedDate(2002, 1, 4); Calendar endDateExpected = new GregorianCalendar(); + endDateExpected.clear(); endDateExpected.set(2002, 1, 4, 23, 59, 59); endDateExpected.set(Calendar.MILLISECOND, 999); final String defaultField = "default"; diff --git a/src/test/org/apache/lucene/TestSearch.java b/src/test/org/apache/lucene/TestSearch.java index f30316da4d3..a5076f50a40 100644 --- a/src/test/org/apache/lucene/TestSearch.java +++ b/src/test/org/apache/lucene/TestSearch.java @@ -134,6 +134,7 @@ public class TestSearch extends LuceneTestCase { static long Time(int year, int month, int day) { GregorianCalendar calendar = new GregorianCalendar(); + calendar.clear(); calendar.set(year, month, day); return calendar.getTime().getTime(); } diff --git a/src/test/org/apache/lucene/document/TestDateTools.java b/src/test/org/apache/lucene/document/TestDateTools.java index e846288f40b..5fcea6062cb 100644 --- a/src/test/org/apache/lucene/document/TestDateTools.java +++ b/src/test/org/apache/lucene/document/TestDateTools.java @@ -59,6 +59,7 @@ public class TestDateTools extends LocalizedTestCase { public void testStringtoTime() throws ParseException { long time = DateTools.stringToTime("197001010000"); Calendar cal = new GregorianCalendar(); + cal.clear(); cal.set(1970, 0, 1, // year=1970, month=january, day=1 0, 0, 0); // hour, minute, second cal.set(Calendar.MILLISECOND, 0); @@ -73,6 +74,7 @@ public class TestDateTools extends LocalizedTestCase { public void testDateAndTimetoString() throws ParseException { Calendar cal = new GregorianCalendar(); + cal.clear(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.set(2004, 1, 3, // year=2004, month=february(!), day=3 22, 8, 56); // hour, minute, second @@ -137,6 +139,7 @@ public class TestDateTools extends LocalizedTestCase { public void testRound() { Calendar cal = new GregorianCalendar(); + cal.clear(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.set(2004, 1, 3, // year=2004, month=february(!), day=3 22, 8, 56); // hour, minute, second diff --git a/src/test/org/apache/lucene/queryParser/TestQueryParser.java b/src/test/org/apache/lucene/queryParser/TestQueryParser.java index a13a0c6ad25..736b55969d2 100644 --- a/src/test/org/apache/lucene/queryParser/TestQueryParser.java +++ b/src/test/org/apache/lucene/queryParser/TestQueryParser.java @@ -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); Calendar calendar = new GregorianCalendar(); + calendar.clear(); calendar.set(year, month, day); - if (extendLastDate) { - calendar.set(Calendar.HOUR_OF_DAY, 23); - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - calendar.set(Calendar.MILLISECOND, 999); - } + 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()); } /** for testing legacy DateField support */ public void testLegacyDateRange() throws Exception { - String startDate = getLocalizedDate(2002, 1, 1, false); - String endDate = getLocalizedDate(2002, 1, 4, false); + String startDate = getLocalizedDate(2002, 1, 1); + String endDate = getLocalizedDate(2002, 1, 4); Calendar endDateExpected = new GregorianCalendar(); + endDateExpected.clear(); endDateExpected.set(2002, 1, 4, 23, 59, 59); endDateExpected.set(Calendar.MILLISECOND, 999); assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null, @@ -570,9 +570,10 @@ public class TestQueryParser extends LocalizedTestCase { } public void testDateRange() throws Exception { - String startDate = getLocalizedDate(2002, 1, 1, false); - String endDate = getLocalizedDate(2002, 1, 4, false); + String startDate = getLocalizedDate(2002, 1, 1); + String endDate = getLocalizedDate(2002, 1, 4); Calendar endDateExpected = new GregorianCalendar(); + endDateExpected.clear(); endDateExpected.set(2002, 1, 4, 23, 59, 59); endDateExpected.set(Calendar.MILLISECOND, 999); final String defaultField = "default";