Return-Path: Delivered-To: apmail-incubator-lucene-net-commits-archive@minotaur.apache.org Received: (qmail 75326 invoked from network); 13 Nov 2009 22:48:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Nov 2009 22:48:14 -0000 Received: (qmail 79635 invoked by uid 500); 13 Nov 2009 22:48:14 -0000 Delivered-To: apmail-incubator-lucene-net-commits-archive@incubator.apache.org Received: (qmail 79587 invoked by uid 500); 13 Nov 2009 22:48:14 -0000 Mailing-List: contact lucene-net-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@incubator.apache.org Delivered-To: mailing list lucene-net-commits@incubator.apache.org Received: (qmail 79578 invoked by uid 99); 13 Nov 2009 22:48:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Nov 2009 22:48:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Nov 2009 22:48:04 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 296E623888BD; Fri, 13 Nov 2009 22:47:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: lucene-net-commits@incubator.apache.org From: aroush@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091113224742.296E623888BD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ /// 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); } /// Converts a millisecond time to a string suitable for indexing. @@ -95,41 +92,38 @@ /// 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); } /// Converts a string produced by timeToString or @@ -146,10 +140,7 @@ /// public static long StringToTime(System.String dateString) { - lock (typeof(Lucene.Net.Documents.DateTools)) - { - return StringToDate(dateString).Ticks; - } + return StringToDate(dateString).Ticks; } /// Converts a string produced by timeToString or @@ -166,70 +157,67 @@ /// 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; } /// Limit a date's resolution. For example, the date 2004-09-21 13:50:11 @@ -244,10 +232,7 @@ /// 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)); } /// Limit a date's resolution. For example, the date 1095767411000 @@ -256,6 +241,7 @@ /// Resolution.MONTH. /// /// + /// The time in milliseconds (not ticks). /// The desired resolution of the date to be returned /// /// the date with all values more precise than resolution @@ -263,59 +249,56 @@ /// 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; } /// Specifies the time granularity. 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 @@ False - ..\..\..\SharpZipLib\netcf-20\ICSharpCode.SharpZipLib.dll + .\ICSharpCode.SharpZipLib.dll System @@ -900,6 +900,7 @@ + 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) - { - } /// [Test] - public static void TestBefore() + public virtual void TestBefore() { // create an index RAMDirectory indexStore = new RAMDirectory(); @@ -103,7 +100,7 @@ /// [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 @@ DemoLib ..\Demo\DemoLib\bin\Release\DemoLib.dll - + + False + ..\..\..\..\..\Lucene-2.9\SharpZipLib\netcf-20\ICSharpCode.SharpZipLib.dll + Lucene.Net ..\Lucene.Net\bin\Debug\Lucene.Net.dll - - + + False + ..\..\..\..\..\Lucene-2.9\NUnit.Net\NUnit-2.5.2.9222\bin\net-2.0\framework\nunit.framework.dll + + + False + ..\..\..\..\..\Lucene-2.9\NUnit.Net\NUnit-2.5.2.9222\bin\net-2.0\framework\nunit.mocks.dll + System