You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "Neal Granroth (JIRA)" <ji...@apache.org> on 2011/04/12 00:05:06 UTC

[Lucene.Net] [jira] [Created] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()

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


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

[Lucene.Net] [jira] [Commented] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()

Posted by "Neal Granroth (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENENET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13020468#comment-13020468 ] 

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

I looked at the patch.  It will clear the exception, but DateField will not work correctly.

The StringToDate() method does not apply the reverse of the TicksToMilliseconds conversion which the DateToString() method applied.  Also, the StringToDate() method does not apply the reverse of the UTC offset which the DateToString() method applied.

Would you prefer separate JIRA issues for these?


> 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

[Lucene.Net] [jira] [Closed] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()

Posted by "Digy (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENENET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Digy closed LUCENENET-409.
--------------------------

       Resolution: Fixed
    Fix Version/s: Lucene.Net 2.9.4
         Assignee: Digy

> 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
>            Assignee: Digy
>             Fix For: Lucene.Net 2.9.4
>
>         Attachments: DateField.patch, LUCENENET-409.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

[Lucene.Net] [jira] [Commented] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()

Posted by "Neal Granroth (JIRA)" <ji...@apache.org>.
    [ 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

[Lucene.Net] [jira] [Updated] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()

Posted by "Digy (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENENET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Digy updated LUCENENET-409:
---------------------------

    Attachment: DateField.patch

Hi Neal,
Can you try the patch?

DIGY

> 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

[Lucene.Net] [jira] [Updated] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()

Posted by "Digy (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENENET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Digy updated LUCENENET-409:
---------------------------

    Attachment: LUCENENET-409.patch

> 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, LUCENENET-409.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

[Lucene.Net] [jira] [Commented] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()

Posted by "Digy (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENENET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13021102#comment-13021102 ] 

Digy commented on LUCENENET-409:
--------------------------------

Hi Neal,
I'll commit the final patch which also fixes the bug in SupportClass.Number.ToInt64.

DIGY



> 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, LUCENENET-409.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

[Lucene.Net] [jira] [Commented] (LUCENENET-409) Invalid Base exception in DateField.StringToTime()

Posted by "Digy (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENENET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13020569#comment-13020569 ] 

Digy commented on LUCENENET-409:
--------------------------------

No need for a separate issue.
Here is the code from Lucene.Net 2.4.0.
{code}
public static System.DateTime StringToDate(System.String s)
{
	long ticks = StringToTime(s) * TimeSpan.TicksPerMillisecond;
	System.DateTime date = new System.DateTime(1970, 1, 1);
	date = date.AddTicks(ticks);
	date = date.Add(TimeZone.CurrentTimeZone.GetUtcOffset(date));
	return date;
}
{code}

It is lost somehow in 2.9

Is this OK?

DIGY

> 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