lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neal Granroth (JIRA)" <j...@apache.org>
Subject [Lucene.Net] [jira] [Commented] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()
Date Mon, 18 Apr 2011 15:26:05 GMT

    [ https://issues.apache.org/jira/browse/LUCENENET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13021065#comment-13021065
] 

Neal Granroth commented on LUCENENET-409:
-----------------------------------------

Yes, that works.
However, when I ran some tests I found that the patch for StringToTime() doesn't work right.
It needs to be this:
 public static long StringToTime(System.String s)
 {
    return SupportClass.Number.Parse(s, SupportClass.Number.MAX_RADIX);
 }

I don't quite understand why, as the SupportClass.Number.ToInt64() method is very similar;
but when it is used the returned time is always 1970.

Original Time: 4/18/2011 10:13:33 AM
Returned Time: 1/21/1970 4:08:42 AM
Diff Secs: -1301378690.68857
String: "0gmnjogq8"

If I use SupportClass.Number.Parse() instead I see this:

Original Time: 4/18/2011 10:16:09 AM
Returned Time: 4/18/2011 10:16:09 AM
Diff Secs: -7.03E-05
String: "0gmnjrt5d"

Here's the small test program in case you'd like to put it into a unit-test:
 using System;
 using System.Collections.Generic;
 using System.Text;
 using DateField = Lucene.Net.Documents.DateField;
 using SC = System.Console;

 namespace DateCheck
 {
	class Program
	{
		static void Main(string[] args)
		{
			DateTime dtTest1 = DateTime.Now.ToLocalTime();
			string strTest = DateField.DateToString(dtTest1);
			DateTime dtTest2 = DateField.StringToDate( strTest );

			SC.WriteLine("Original Time: {0}",dtTest1.ToString());
			SC.WriteLine("Returned Time: {0}",dtTest2.ToString());
			SC.WriteLine("Diff Secs: {0}",(dtTest2-dtTest1).TotalSeconds);
			SC.WriteLine("String: \"{0}\"",strTest);
		}
	}
 }




> Invalid Base exception in DateField.StringToTime()
> --------------------------------------------------
>
>                 Key: LUCENENET-409
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-409
>             Project: Lucene.Net
>          Issue Type: Bug
>          Components: Lucene.Net Core
>    Affects Versions: Lucene.Net 2.9.4
>            Reporter: Neal Granroth
>         Attachments: DateField.patch
>
>
> The Lucene.Net.Documents.DateField.StringToTime() method called by StringToDate() appears
to specify an invalid value for the base in the .NET Convert.ToInt64() call.  When a DateField
value in a legacy index is read, or Lucene.NET 2.9.4 is used with legacy code that relies
upon DateField, the following exception occurs whenever StringToDate() is called:
> System.ArgumentException: Invalid Base.
>    at System.Convert.ToInt64(String value, Int32 fromBase)
>    at Lucene.Net.Documents.DateField.StringToTime(String s)
>    at Lucene.Net.Documents.DateField.StringToDate(String s)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message