lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r438340 - in /incubator/lucene.net/trunk/C#/src: Lucene.Net/QueryParser/QueryParser.cs Test/QueryParser/TestQueryParser.cs
Date Wed, 30 Aug 2006 03:47:04 GMT
Author: aroush
Date: Tue Aug 29 20:47:03 2006
New Revision: 438340

URL: http://svn.apache.org/viewvc?rev=438340&view=rev
Log: (empty)

Modified:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/QueryParser.cs
    incubator/lucene.net/trunk/C#/src/Test/QueryParser/TestQueryParser.cs

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/QueryParser.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/QueryParser/QueryParser.cs?rev=438340&r1=438339&r2=438340&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/QueryParser.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/QueryParser.cs Tue Aug 29 20:47:03
2006
@@ -461,8 +461,26 @@
 			}
 			try
 			{
-                System.DateTime d1 = System.DateTime.Parse(part1, locale);
-                System.DateTime d2 = System.DateTime.Parse(part2, locale);
+                System.DateTime d1;
+                System.DateTime d2;
+
+                try
+                {
+                    d1 = System.DateTime.Parse(part1, locale);
+                }
+                catch (System.Exception)
+                {
+                    d1 = System.DateTime.Parse(part1);
+                }
+                try
+                {
+                    d2 = System.DateTime.Parse(part2, locale);
+                }
+                catch (System.Exception)
+                {
+                    d2 = System.DateTime.Parse(part2);
+                }
+
                 if (inclusive)
                 {
                     // The user can only specify the date, not the time, so make sure
@@ -470,10 +488,10 @@
                     // include all documents:
                     System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar();
                     System.DateTime tempDate = d2;
-                    d2 = tempDate.AddHours(23 - tempDate.Hour);
-                    d2 = tempDate.AddMinutes(59 - tempDate.Minute);
-                    d2 = tempDate.AddMinutes(59 - tempDate.Second);
-                    d2 = tempDate.AddMinutes(999 - tempDate.Millisecond);
+                    d2 = d2.AddHours(23 - tempDate.Hour);
+                    d2 = d2.AddMinutes(59 - tempDate.Minute);
+                    d2 = d2.AddSeconds(59 - tempDate.Second);
+                    d2 = d2.AddMilliseconds(999 - tempDate.Millisecond);
                 }
                 part1 = DateField.DateToString(d1);
                 part2 = DateField.DateToString(d2);

Modified: incubator/lucene.net/trunk/C#/src/Test/QueryParser/TestQueryParser.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/QueryParser/TestQueryParser.cs?rev=438340&r1=438339&r2=438340&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/QueryParser/TestQueryParser.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/QueryParser/TestQueryParser.cs Tue Aug 29 20:47:03
2006
@@ -378,22 +378,33 @@
 		
 		public virtual System.String GetDate(System.String s)
 		{
-			return DateField.DateToString(System.DateTime.Parse(s));
+            System.DateTime tempAux = System.DateTime.Parse(s);
+            return DateField.DateToString(tempAux);
 		}
 		
-		public virtual System.String GetLocalizedDate(int year, int month, int day)
+		private System.String GetLocalizedDate(int year, int month, int day, bool extendLastDate)
 		{
-            return new System.DateTime(year, month, day).ToString("MM/d/yyy");
+            System.DateTime temp = new System.DateTime(year, month, day);
+			if (extendLastDate)
+			{
+                temp = temp.AddHours(23);
+                temp = temp.AddMinutes(59);
+                temp = temp.AddSeconds(59);
+                temp = temp.AddMilliseconds(999);
+			}
+            return temp.ToString("MM/d/yyy");
 		}
 		
 		[Test]
         public virtual void  TestDateRange()
 		{
-			System.String startDate = GetLocalizedDate(2002, 1, 1);
-			System.String endDate = GetLocalizedDate(2002, 1, 4);
-			AssertQueryEquals("[ " + startDate + " TO " + endDate + "]", null, "[" + GetDate(startDate)
+ " TO " + GetDate(endDate) + "]");
-			AssertQueryEquals("{  " + startDate + "    " + endDate + "   }", null, "{" + GetDate(startDate)
+ " TO " + GetDate(endDate) + "}");
-		}
+            System.String startDate = GetLocalizedDate(2002, 2, 1, false);
+            System.String endDate = GetLocalizedDate(2002, 2, 4, false);
+            System.DateTime endDateExpected = new System.DateTime(2002, 2, 4, 23, 59, 59);
+            endDateExpected = endDateExpected.AddMilliseconds(999);
+            AssertQueryEquals("[ " + startDate + " TO " + endDate + "]", null, "[" + GetDate(startDate)
+ " TO " + DateField.DateToString(endDateExpected) + "]");
+            AssertQueryEquals("{  " + startDate + "    " + endDate + "   }", null, "{" +
GetDate(startDate) + " TO " + GetDate(endDate) + "}");
+        }
 		
 		[Test]
         public virtual void  TestEscaped()
@@ -648,7 +659,7 @@
         {
             Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document();
             d.Add(new Lucene.Net.Documents.Field("f", content, Lucene.Net.Documents.Field.Store.YES,
Lucene.Net.Documents.Field.Index.TOKENIZED));
-            System.DateTime tempAux = new System.DateTime(year, month - 1, day, hour, minute,
second);
+            System.DateTime tempAux = new System.DateTime(year, month, day, hour, minute,
second);
             d.Add(new Lucene.Net.Documents.Field("date", DateField.DateToString(tempAux),
Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.UN_TOKENIZED));
             iw.AddDocument(d);
         }



Mime
View raw message