Why is this a Not a legal OleAut date with a TimeSpan of 100 hours and 100 minutes

dal*_*ale 1 c# ole date

I'm trying to create a date from a TimeSpan that has 100 hours and 100 minutes but i'm gettin the error:

Run-time exception (line 9): Not a legal OleAut date.

Stack Trace:

[System.OverflowException: Not a legal OleAut date.] at System.DateTime.TicksToOADate(Int64 value)

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello World");
        TimeSpan timeSpan = TimeSpan.FromHours(100) + TimeSpan.FromMinutes(100);
        var OADate = DateTime.FromOADate((DateTime.MinValue.AddTicks(timeSpan.Ticks)).ToOADate());

    }
}
Run Code Online (Sandbox Code Playgroud)

This is to link in with a legacy value in the db from vb6.

It works with small hour and minutes values but fails with this, any ideas?

Created a Fiddle

Dmi*_*nko 5

让我们看一下您要转换成的日期OADate

TimeSpan timeSpan = TimeSpan.FromHours(100) + TimeSpan.FromMinutes(100);

var OADate = DateTime.MinValue.AddTicks(timeSpan.Ticks);

Console.WriteLine(OADate.ToString("d MMMM yyyy HH:mm:ss", CultureInfo.InvariantCulture));
Run Code Online (Sandbox Code Playgroud)

你会得到这个

5 January 0001 05:40:00
Run Code Online (Sandbox Code Playgroud)

但根据手册粗体是我的)

基本的OLE自动化日期是1899年12月30日午夜。 最小的 OLE自动化日期是0100年1月1日午夜。OLE自动化日期的最大值与9999年12月31日的最后时刻DateTime.MaxValue相同。

这就是为什么DateTime.MinValue.AddTicks(timeSpan.Ticks).ToOADate()非法的(OADate 低于最小值),并且引发了异常。