DateTimes
The DateTimes class contains common operations on Date and Time values.
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints
{
public static class DateTimes
{
[System.Runtime.CompilerServices.NullableContext(2)]
[return: System.Runtime.CompilerServices.Nullable(1)]
internal static object Difference(object x, object y)
{
TimeSpan timeSpan;
if (x is DateTime) {
DateTime d = (DateTime)x;
if (y is DateTime) {
DateTime d2 = (DateTime)y;
timeSpan = d - d2;
return timeSpan.Duration();
}
}
if (x is TimeSpan) {
TimeSpan t = (TimeSpan)x;
if (y is TimeSpan) {
TimeSpan t2 = (TimeSpan)y;
timeSpan = t - t2;
return timeSpan.Duration();
}
}
if (x is DateTimeOffset) {
DateTimeOffset left = (DateTimeOffset)x;
if (y is DateTimeOffset) {
DateTimeOffset right = (DateTimeOffset)y;
timeSpan = left - right;
return timeSpan.Duration();
}
}
throw new ArgumentException("Both arguments must be DateTime, DateTimeOffset or TimeSpan");
}
}
}