Question

I would like to use next code:

long long DateTimeToTimeT(System::DateTime dt)
{
    System::DateTime epoch(1970, 1, 1, 0, 0, 0, 0);
    long long totalSeconds = (dt - epoch).TotalSeconds;

    return totalSeconds >= 0 ? totalSeconds : 0;
}

So question is: Is it exception safe or I should handle some errors here?

I mean: Is is safe to convert from double (which is TotalSeconds) to long long in such case?

No correct solution

OTHER TIPS

Yes, it is safe: the subtraction of two dates never throws (http://msdn.microsoft.com/en-us/library/1905yhe2(v=vs.110).aspx) since TimeSpan covers a much larger interval than valid dates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top