lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r836043 - in /incubator/lucene.net/trunk/C#/src: Lucene.Net/Document/DateTools.cs Lucene.Net/Lucene.Net.csproj Test/Document/TestDateTools.cs Test/Search/TestDateFilter.cs Test/Test.csproj
Date Fri, 13 Nov 2009 22:47:42 GMT
Author: aroush
Date: Fri Nov 13 22:47:41 2009
New Revision: 836043

URL: http://svn.apache.org/viewvc?rev=836043&view=rev
Log:
Fixed NUnit test-cases for: TestDateTools and TestDateFilter

Modified:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Document/DateTools.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Lucene.Net.csproj
    incubator/lucene.net/trunk/C#/src/Test/Document/TestDateTools.cs
    incubator/lucene.net/trunk/C#/src/Test/Search/TestDateFilter.cs
    incubator/lucene.net/trunk/C#/src/Test/Test.csproj

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Document/DateTools.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Document/DateTools.cs?rev=836043&r1=836042&r2=836043&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Document/DateTools.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Document/DateTools.cs Fri Nov 13 22:47:41
2009
@@ -76,10 +76,7 @@
 		/// </returns>
 		public static System.String DateToString(System.DateTime date, Resolution resolution)
 		{
-			lock (typeof(Lucene.Net.Documents.DateTools))
-			{
-				return TimeToString(date.Ticks, resolution);
-			}
+			return TimeToString(date.Ticks / TimeSpan.TicksPerMillisecond, resolution);
 		}
 		
 		/// <summary> Converts a millisecond time to a string suitable for indexing.
@@ -95,41 +92,38 @@
 		/// </returns>
 		public static System.String TimeToString(long time, Resolution resolution)
 		{
-			lock (typeof(Lucene.Net.Documents.DateTools))
+            System.DateTime date = new System.DateTime(Round(time, resolution));
+			
+			if (resolution == Resolution.YEAR)
 			{
-                System.DateTime date = new System.DateTime(Round(time, resolution));
-				
-				if (resolution == Resolution.YEAR)
-				{
-					return date.ToString(YEAR_FORMAT);
-				}
-				else if (resolution == Resolution.MONTH)
-				{
-					return date.ToString(MONTH_FORMAT);
-				}
-				else if (resolution == Resolution.DAY)
-				{
-					return date.ToString(DAY_FORMAT);
-				}
-				else if (resolution == Resolution.HOUR)
-				{
-					return date.ToString(HOUR_FORMAT);
-				}
-				else if (resolution == Resolution.MINUTE)
-				{
-					return date.ToString(MINUTE_FORMAT);
-				}
-				else if (resolution == Resolution.SECOND)
-				{
-					return date.ToString(SECOND_FORMAT);
-				}
-				else if (resolution == Resolution.MILLISECOND)
-				{
-					return date.ToString(MILLISECOND_FORMAT);
-				}
-				
-				throw new System.ArgumentException("unknown resolution " + resolution);
+				return date.ToString(YEAR_FORMAT);
+			}
+			else if (resolution == Resolution.MONTH)
+			{
+				return date.ToString(MONTH_FORMAT);
+			}
+			else if (resolution == Resolution.DAY)
+			{
+				return date.ToString(DAY_FORMAT);
+			}
+			else if (resolution == Resolution.HOUR)
+			{
+				return date.ToString(HOUR_FORMAT);
+			}
+			else if (resolution == Resolution.MINUTE)
+			{
+				return date.ToString(MINUTE_FORMAT);
 			}
+			else if (resolution == Resolution.SECOND)
+			{
+				return date.ToString(SECOND_FORMAT);
+			}
+			else if (resolution == Resolution.MILLISECOND)
+			{
+				return date.ToString(MILLISECOND_FORMAT);
+			}
+			
+			throw new System.ArgumentException("unknown resolution " + resolution);
 		}
 		
 		/// <summary> Converts a string produced by <code>timeToString</code>
or
@@ -146,10 +140,7 @@
 		/// </summary>
 		public static long StringToTime(System.String dateString)
 		{
-			lock (typeof(Lucene.Net.Documents.DateTools))
-			{
-				return StringToDate(dateString).Ticks;
-			}
+			return StringToDate(dateString).Ticks;
 		}
 		
 		/// <summary> Converts a string produced by <code>timeToString</code>
or
@@ -166,70 +157,67 @@
 		/// </summary>
 		public static System.DateTime StringToDate(System.String dateString)
 		{
-			lock (typeof(Lucene.Net.Documents.DateTools))
-			{
-                System.DateTime date;
-                if (dateString.Length == 4)
-                {
-                    date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
-                        1, 1, 0, 0, 0, 0);
-                }
-                else if (dateString.Length == 6)
-                {
-                    date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
-                        Convert.ToInt16(dateString.Substring(4, 2)),
-                        1, 0, 0, 0, 0);
-                }
-                else if (dateString.Length == 8)
-                {
-                    date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
-                        Convert.ToInt16(dateString.Substring(4, 2)),
-                        Convert.ToInt16(dateString.Substring(6, 2)),
-                        0, 0, 0, 0);
-                }
-                else if (dateString.Length == 10)
-                {
-                    date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
-                        Convert.ToInt16(dateString.Substring(4, 2)),
-                        Convert.ToInt16(dateString.Substring(6, 2)),
-                        Convert.ToInt16(dateString.Substring(8, 2)),
-                        0, 0, 0);
-                }
-                else if (dateString.Length == 12)
-                {
-                    date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
-                        Convert.ToInt16(dateString.Substring(4, 2)),
-                        Convert.ToInt16(dateString.Substring(6, 2)),
-                        Convert.ToInt16(dateString.Substring(8, 2)),
-                        Convert.ToInt16(dateString.Substring(10, 2)),
-                        0, 0);
-                }
-                else if (dateString.Length == 14)
-                {
-                    date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
-                        Convert.ToInt16(dateString.Substring(4, 2)),
-                        Convert.ToInt16(dateString.Substring(6, 2)),
-                        Convert.ToInt16(dateString.Substring(8, 2)),
-                        Convert.ToInt16(dateString.Substring(10, 2)),
-                        Convert.ToInt16(dateString.Substring(12, 2)),
-                        0);
-                }
-                else if (dateString.Length == 17)
-                {
-                    date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
-                        Convert.ToInt16(dateString.Substring(4, 2)),
-                        Convert.ToInt16(dateString.Substring(6, 2)),
-                        Convert.ToInt16(dateString.Substring(8, 2)),
-                        Convert.ToInt16(dateString.Substring(10, 2)),
-                        Convert.ToInt16(dateString.Substring(12, 2)),
-                        Convert.ToInt16(dateString.Substring(14, 3)));
-                }
-                else
-                {
-                    throw new System.FormatException("Input is not valid date string: " +
dateString);
-                }
-                return date;
+            System.DateTime date;
+            if (dateString.Length == 4)
+            {
+                date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
+                    1, 1, 0, 0, 0, 0);
+            }
+            else if (dateString.Length == 6)
+            {
+                date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
+                    Convert.ToInt16(dateString.Substring(4, 2)),
+                    1, 0, 0, 0, 0);
+            }
+            else if (dateString.Length == 8)
+            {
+                date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
+                    Convert.ToInt16(dateString.Substring(4, 2)),
+                    Convert.ToInt16(dateString.Substring(6, 2)),
+                    0, 0, 0, 0);
+            }
+            else if (dateString.Length == 10)
+            {
+                date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
+                    Convert.ToInt16(dateString.Substring(4, 2)),
+                    Convert.ToInt16(dateString.Substring(6, 2)),
+                    Convert.ToInt16(dateString.Substring(8, 2)),
+                    0, 0, 0);
             }
+            else if (dateString.Length == 12)
+            {
+                date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
+                    Convert.ToInt16(dateString.Substring(4, 2)),
+                    Convert.ToInt16(dateString.Substring(6, 2)),
+                    Convert.ToInt16(dateString.Substring(8, 2)),
+                    Convert.ToInt16(dateString.Substring(10, 2)),
+                    0, 0);
+            }
+            else if (dateString.Length == 14)
+            {
+                date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
+                    Convert.ToInt16(dateString.Substring(4, 2)),
+                    Convert.ToInt16(dateString.Substring(6, 2)),
+                    Convert.ToInt16(dateString.Substring(8, 2)),
+                    Convert.ToInt16(dateString.Substring(10, 2)),
+                    Convert.ToInt16(dateString.Substring(12, 2)),
+                    0);
+            }
+            else if (dateString.Length == 17)
+            {
+                date = new System.DateTime(Convert.ToInt16(dateString.Substring(0, 4)),
+                    Convert.ToInt16(dateString.Substring(4, 2)),
+                    Convert.ToInt16(dateString.Substring(6, 2)),
+                    Convert.ToInt16(dateString.Substring(8, 2)),
+                    Convert.ToInt16(dateString.Substring(10, 2)),
+                    Convert.ToInt16(dateString.Substring(12, 2)),
+                    Convert.ToInt16(dateString.Substring(14, 3)));
+            }
+            else
+            {
+                throw new System.FormatException("Input is not valid date string: " + dateString);
+            }
+            return date;
 		}
 		
 		/// <summary> Limit a date's resolution. For example, the date <code>2004-09-21
13:50:11</code>
@@ -244,10 +232,7 @@
 		/// </returns>
 		public static System.DateTime Round(System.DateTime date, Resolution resolution)
 		{
-			lock (typeof(Lucene.Net.Documents.DateTools))
-			{
-				return new System.DateTime(Round(date.Ticks, resolution));
-			}
+			return new System.DateTime(Round(date.Ticks / TimeSpan.TicksPerMillisecond, resolution));
 		}
 		
 		/// <summary> Limit a date's resolution. For example, the date <code>1095767411000</code>
@@ -256,6 +241,7 @@
 		/// <code>Resolution.MONTH</code>.
 		/// 
 		/// </summary>
+		/// <param name="time">The time in milliseconds (not ticks).</param>
 		/// <param name="resolution">The desired resolution of the date to be returned
 		/// </param>
 		/// <returns> the date with all values more precise than <code>resolution</code>
@@ -263,59 +249,56 @@
 		/// </returns>
 		public static long Round(long time, Resolution resolution)
 		{
-			lock (typeof(Lucene.Net.Documents.DateTools))
+			System.DateTime dt = new System.DateTime(time * TimeSpan.TicksPerMillisecond);
+			
+			if (resolution == Resolution.YEAR)
+			{
+                dt = dt.AddMonths(1 - dt.Month);
+                dt = dt.AddDays(1 - dt.Day);
+                dt = dt.AddHours(0 - dt.Hour);
+                dt = dt.AddMinutes(0 - dt.Minute);
+                dt = dt.AddSeconds(0 - dt.Second);
+                dt = dt.AddMilliseconds(0 - dt.Millisecond);
+            }
+			else if (resolution == Resolution.MONTH)
+			{
+                dt = dt.AddDays(1 - dt.Day);
+                dt = dt.AddHours(0 - dt.Hour);
+                dt = dt.AddMinutes(0 - dt.Minute);
+                dt = dt.AddSeconds(0 - dt.Second);
+                dt = dt.AddMilliseconds(0 - dt.Millisecond);
+            }
+			else if (resolution == Resolution.DAY)
 			{
-				System.DateTime dt = new System.DateTime(time);
-				
-				if (resolution == Resolution.YEAR)
-				{
-                    dt = dt.AddMonths(1 - dt.Month);
-                    dt = dt.AddDays(1 - dt.Day);
-                    dt = dt.AddHours(0 - dt.Hour);
-                    dt = dt.AddMinutes(0 - dt.Minute);
-                    dt = dt.AddSeconds(0 - dt.Second);
-                    dt = dt.AddMilliseconds(0 - dt.Millisecond);
-                }
-				else if (resolution == Resolution.MONTH)
-				{
-                    dt = dt.AddDays(1 - dt.Day);
-                    dt = dt.AddHours(0 - dt.Hour);
-                    dt = dt.AddMinutes(0 - dt.Minute);
-                    dt = dt.AddSeconds(0 - dt.Second);
-                    dt = dt.AddMilliseconds(0 - dt.Millisecond);
-                }
-				else if (resolution == Resolution.DAY)
-				{
-                    dt = dt.AddHours(0 - dt.Hour);
-                    dt = dt.AddMinutes(0 - dt.Minute);
-                    dt = dt.AddSeconds(0 - dt.Second);
-                    dt = dt.AddMilliseconds(0 - dt.Millisecond);
-                }
-				else if (resolution == Resolution.HOUR)
-				{
-                    dt = dt.AddMinutes(0 - dt.Minute);
-                    dt = dt.AddSeconds(0 - dt.Second);
-                    dt = dt.AddMilliseconds(0 - dt.Millisecond);
-                }
-				else if (resolution == Resolution.MINUTE)
-				{
-                    dt = dt.AddSeconds(0 - dt.Second);
-                    dt = dt.AddMilliseconds(0 - dt.Millisecond);
-                }
-				else if (resolution == Resolution.SECOND)
-				{
-                    dt = dt.AddMilliseconds(0 - dt.Millisecond);
-                }
-				else if (resolution == Resolution.MILLISECOND)
-				{
-					// don't cut off anything
-				}
-				else
-				{
-					throw new System.ArgumentException("unknown resolution " + resolution);
-				}
-				return dt.Ticks;
+                dt = dt.AddHours(0 - dt.Hour);
+                dt = dt.AddMinutes(0 - dt.Minute);
+                dt = dt.AddSeconds(0 - dt.Second);
+                dt = dt.AddMilliseconds(0 - dt.Millisecond);
+            }
+			else if (resolution == Resolution.HOUR)
+			{
+                dt = dt.AddMinutes(0 - dt.Minute);
+                dt = dt.AddSeconds(0 - dt.Second);
+                dt = dt.AddMilliseconds(0 - dt.Millisecond);
+            }
+			else if (resolution == Resolution.MINUTE)
+			{
+                dt = dt.AddSeconds(0 - dt.Second);
+                dt = dt.AddMilliseconds(0 - dt.Millisecond);
+            }
+			else if (resolution == Resolution.SECOND)
+			{
+                dt = dt.AddMilliseconds(0 - dt.Millisecond);
+            }
+			else if (resolution == Resolution.MILLISECOND)
+			{
+				// don't cut off anything
+			}
+			else
+			{
+				throw new System.ArgumentException("unknown resolution " + resolution);
 			}
+			return dt.Ticks;
 		}
 		
 		/// <summary>Specifies the time granularity. </summary>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Lucene.Net.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Lucene.Net.csproj?rev=836043&r1=836042&r2=836043&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Lucene.Net.csproj (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Lucene.Net.csproj Fri Nov 13 22:47:41 2009
@@ -75,7 +75,7 @@
   <ItemGroup>
     <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral,
processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\SharpZipLib\netcf-20\ICSharpCode.SharpZipLib.dll</HintPath>
+      <HintPath>.\ICSharpCode.SharpZipLib.dll</HintPath>
     </Reference>
     <Reference Include="System">
       <Name>System</Name>
@@ -900,6 +900,7 @@
     <Compile Include="Util\UnicodeUtil.cs" />
     <Compile Include="Util\Version.cs" />
     <None Include="Analysis\Standard\StandardTokenizerImpl.jflex" />
+    <None Include="ClassDiagram1.cd" />
     <None Include="Lucene.Net.Search.RemoteSearchable.config" />
     <None Include="Lucene.Net.Search.TestSort.config" />
     <None Include="QueryParser\QueryParser.jj" />

Modified: incubator/lucene.net/trunk/C#/src/Test/Document/TestDateTools.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Document/TestDateTools.cs?rev=836043&r1=836042&r2=836043&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Document/TestDateTools.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Document/TestDateTools.cs Fri Nov 13 22:47:41 2009
@@ -149,11 +149,11 @@
 			
 			// timeToString:
 			cal = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, new System.Globalization.GregorianCalendar());
-			dateString = DateTools.TimeToString(cal.Ticks, DateTools.Resolution.MILLISECOND);
+			dateString = DateTools.TimeToString(cal.Ticks / TimeSpan.TicksPerMillisecond, DateTools.Resolution.MILLISECOND);
 			Assert.AreEqual("19700101000000000", dateString);
 			
 			cal = new System.DateTime(1970, 1, 1, 1, 2, 3, 0, new System.Globalization.GregorianCalendar());
-			dateString = DateTools.TimeToString(cal.Ticks, DateTools.Resolution.MILLISECOND);
+			dateString = DateTools.TimeToString(cal.Ticks / TimeSpan.TicksPerMillisecond, DateTools.Resolution.MILLISECOND);
 			Assert.AreEqual("19700101010203000", dateString);
 		}
 		
@@ -185,11 +185,11 @@
 			Assert.AreEqual("2004-02-03 22:08:56:333", IsoFormat(dateMillisecond));
 			
 			// long parameter:
-			long dateYearLong = DateTools.Round(date.Ticks, DateTools.Resolution.YEAR);
+			long dateYearLong = DateTools.Round(date.Ticks / TimeSpan.TicksPerMillisecond, DateTools.Resolution.YEAR);
 			System.DateTime tempAux = new System.DateTime(dateYearLong);
 			Assert.AreEqual("2004-01-01 00:00:00:000", IsoFormat(tempAux));
 			
-			long dateMillisecondLong = DateTools.Round(date.Ticks, DateTools.Resolution.MILLISECOND);
+			long dateMillisecondLong = DateTools.Round(date.Ticks / TimeSpan.TicksPerMillisecond,
DateTools.Resolution.MILLISECOND);
 			System.DateTime tempAux2 = new System.DateTime(dateMillisecondLong);
 			Assert.AreEqual("2004-02-03 22:08:56:333", IsoFormat(tempAux2));
 		}

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestDateFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestDateFilter.cs?rev=836043&r1=836042&r2=836043&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestDateFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestDateFilter.cs Fri Nov 13 22:47:41 2009
@@ -40,13 +40,10 @@
     [TestFixture]
 	public class TestDateFilter:LuceneTestCase
 	{
-		public TestDateFilter(System.String name):base(name)
-		{
-		}
 		
 		/// <summary> </summary>
 		[Test]
-		public static void  TestBefore()
+		public virtual void  TestBefore()
 		{
 			// create an index
 			RAMDirectory indexStore = new RAMDirectory();
@@ -103,7 +100,7 @@
 		
 		/// <summary> </summary>
 		[Test]
-		public static void  TestAfter()
+		public virtual void  TestAfter()
 		{
 			// create an index
 			RAMDirectory indexStore = new RAMDirectory();

Modified: incubator/lucene.net/trunk/C#/src/Test/Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Test.csproj?rev=836043&r1=836042&r2=836043&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Test.csproj (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Test.csproj Fri Nov 13 22:47:41 2009
@@ -78,13 +78,22 @@
       <Name>DemoLib</Name>
       <HintPath>..\Demo\DemoLib\bin\Release\DemoLib.dll</HintPath>
     </Reference>
-    <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.4.369, Culture=neutral,
processorArchitecture=MSIL" />
+    <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral,
processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\Lucene-2.9\SharpZipLib\netcf-20\ICSharpCode.SharpZipLib.dll</HintPath>
+    </Reference>
     <Reference Include="Lucene.Net">
       <Name>Lucene.Net</Name>
       <HintPath>..\Lucene.Net\bin\Debug\Lucene.Net.dll</HintPath>
     </Reference>
-    <Reference Include="nunit.framework, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77,
processorArchitecture=MSIL" />
-    <Reference Include="nunit.mocks, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77,
processorArchitecture=MSIL" />
+    <Reference Include="nunit.framework, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77,
processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\Lucene-2.9\NUnit.Net\NUnit-2.5.2.9222\bin\net-2.0\framework\nunit.framework.dll</HintPath>
+    </Reference>
+    <Reference Include="nunit.mocks, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77,
processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\Lucene-2.9\NUnit.Net\NUnit-2.5.2.9222\bin\net-2.0\framework\nunit.mocks.dll</HintPath>
+    </Reference>
     <Reference Include="System">
       <Name>System</Name>
     </Reference>



Mime
View raw message