[Mono-bugs] [Bug 322934] StructLayout for DateTime passed to managed code

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Oct 6 19:51:04 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=322934

User tom_hindle at sil.org added comment
http://bugzilla.novell.com/show_bug.cgi?id=322934#c4





--- Comment #4 from tom hindle <tom_hindle at sil.org>  2009-10-06 17:51:03 MDT ---
Here is how to convert DateTime to DATE and vice-versa.

// DATE is days from midnight, 30 December 1899
// DateTime 100-nanosecond (ticks) since 12:00:00 midnight, January 1, 0001 

const long OneHundredNanosecondsInDay = 864000000000;
const long OleDateBaseInTicks = 599264352000000000;

static DateTime ConvertOleDateToDateTime(double date)
{
    return new DateTime((long)(date * OneHundredNanosecondsInDay) +
OleDateBaseInTicks);
}

static double ConvertOleDateToDateTime(DateTime dateTime)
{            
    return (dateTime.Ticks - OleDateBaseInTicks) / OneHundredNanosecondsInDay;  
}


I have compared this to what .NET (3.5) does and it seems the same except that
NET converts DateTime(1899, 12, 30); and DateTime(0001, 1, 1); to a DATE value
of 0. (a bug in .NET?)

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list