Menu

#4 Datefield string conversions are broken

open
nobody
None
5
2013-01-10
2005-02-03
mike belshe
No

Thanks for creating dotlucene!

The date mechanism is better than the old lucene.net's
1.3 based product. But its still got a bug converting
between strings and dates and back again.

Bug Proof
---------
Here is a quick test to confirm the bug:

DateTime foo = new DateTime(2000,5,5,12,12,12,0);
string strFoo = DateField.DateToString(foo);
DateTime foo2 = DateField.StringToDate(strFoo);

Notice that foo2 is not the same as foo!

Fix
---
Here is the simple fix (from Document/DateField.cs)

/// <summary>Converts a string-encoded date into a
Date object. </summary>
public static System.DateTime StringToDate
(System.String s)
{
// XXXMB - this is a bug.
//return new System.DateTime(StringToTime
(s));
long ticksSince1970 =
SupportClass.Number.Parse(s, 36) *
TimeSpan.TicksPerMillisecond;
return new DateTime(1970, 1, 1) + new
TimeSpan(ticksSince1970);
}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB