public void ToDateTime_Overflow() { var timespec = new Timespec(long.MaxValue - 100, 0); Assert.AreNotEqual(Timespec.InfFuture, timespec); Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime()); Assert.AreEqual(DateTime.MinValue, new Timespec(long.MinValue + 100, 0).ToDateTime()); }
public void ToDateTime_OutOfDateTimeRange() { // DateTime range goes up to year 9999, 20000 years from now should // be out of range. long seconds = 20000L * 365L * 24L * 3600L; var timespec = new Timespec(seconds, 0); Assert.AreNotEqual(Timespec.InfFuture, timespec); Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime()); Assert.AreEqual(DateTime.MinValue, new Timespec(-seconds, 0).ToDateTime()); }
public void ToDateTime_Overflow() { // we can only get overflow in ticks arithmetic on 64-bit if (IntPtr.Size == 8) { var timespec = new Timespec(new IntPtr(long.MaxValue - 100), 0); Assert.AreNotEqual(Timespec.InfFuture, timespec); Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime()); Assert.AreEqual(DateTime.MinValue, new Timespec(new IntPtr(long.MinValue + 100), 0).ToDateTime()); } else { Console.WriteLine("Test cannot be run on this platform, skipping the test."); } }
public void ToDateTime_OutOfDateTimeRange() { // we can only get out of range on 64-bit, on 32 bit the max // timestamp is ~ Jan 19 2038, which is far within range of DateTime // same case for min value. if (IntPtr.Size == 8) { // DateTime range goes up to year 9999, 20000 years from now should // be out of range. long seconds = 20000L * 365L * 24L * 3600L; var timespec = new Timespec(new IntPtr(seconds), 0); Assert.AreNotEqual(Timespec.InfFuture, timespec); Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime()); Assert.AreEqual(DateTime.MinValue, new Timespec(new IntPtr(-seconds), 0).ToDateTime()); } else { Console.WriteLine("Test cannot be run on this platform, skipping the test"); } }