public void IntegralConversions() { DateTime t1 = new DateTime(2006, 7, 17, 10, 56, 56); const long u1 = 1153133816; DateTime t2 = new DateTime(2006, 7, 17, 11, 00, 44); const long u2 = 1153134044; Assert.AreEqual(t1, UnixTime.ToDateTime(u1).ToUniversalTime()); Assert.AreEqual(t2, UnixTime.ToDateTime(u2).ToUniversalTime()); Assert.AreEqual(u1, UnixTime.ToInt64(t1.ToLocalTime())); Assert.AreEqual(u2, UnixTime.ToInt64(t2.ToLocalTime())); }
public void Milliseconds() { DateTime t1 = new DateTime(2006, 7, 17, 10, 56, 56, 456); const double u1 = 1153133816.456; DateTime t2 = new DateTime(2006, 7, 17, 11, 00, 44, 567); const double u2 = 1153134044.567; DateTime ut1 = UnixTime.ToDateTime(u1).ToUniversalTime(); Assert.AreEqual(t1, ut1, "ms expected = {0}, ms actual = {1}", t1.Millisecond, ut1.Millisecond); DateTime ut2 = UnixTime.ToDateTime(u2).ToUniversalTime(); Assert.AreEqual(t2, ut2, "ms expected = {0}, ms actual = {1}", t2.Millisecond, ut2.Millisecond); Assert.AreEqual(u1, UnixTime.ToDouble(t1.ToLocalTime()), 0.0001); Assert.AreEqual(u2, UnixTime.ToDouble(t2.ToLocalTime()), 0.0001); }
public void Milliseconds() { DateTime t1 = new DateTime(2006, 7, 17, 10, 56, 56, 456); const double u1 = 1153133816.456; DateTime t2 = new DateTime(2006, 7, 17, 11, 00, 44, 567); const double u2 = 1153134044.567; DateTime ut1 = UnixTime.ToDateTime(u1).ToUniversalTime(); Assert.AreEqual(t1, ut1, "ms expected = {0}, ms actual = {1}", t1.Millisecond, ut1.Millisecond); DateTime ut2 = UnixTime.ToDateTime(u2).ToUniversalTime(); Assert.AreEqual(t2, ut2, "ms expected = {0}, ms actual = {1}", t2.Millisecond, ut2.Millisecond); Assert.AreEqual(u1, UnixTime.ToDouble(t1.ToLocalTime()), 0.0001); Assert.AreEqual(u2, UnixTime.ToDouble(t2.ToLocalTime()), 0.0001); Assert.AreEqual(new DateTime(1098, 7, 6, 5, 43, 21, 234), UnixTime.ToDateTime(-27501531398.766).ToUniversalTime()); Assert.AreEqual(UnixTime.EpochUtc.AddMilliseconds(+123), UnixTime.ToDateTime(0, +123).ToUniversalTime()); Assert.AreEqual(UnixTime.EpochUtc.AddMilliseconds(-123), UnixTime.ToDateTime(0, -123).ToUniversalTime()); }
public void CannotOverflowMilliseconds() { UnixTime.ToDateTime(0, 1000); }
public void Negative() { Assert.AreEqual(new DateTime(1098, 7, 6, 5, 43, 21, 234), UnixTime.ToDateTime(-27501531398, -766).ToUniversalTime()); }
public void CannotSpecifyNegativeTimeWithPositiveMilliseconds() { UnixTime.ToDateTime(-123, 456); }
public void Maximum() { Assert.AreEqual(new DateTime(3000, 12, 31, 23, 59, 59), UnixTime.ToDateTime(32535215999L).ToUniversalTime()); }
public void CannotOverflowNegativeMilliseconds() { UnixTime.ToDateTime(0, -1000); }
public void CannotSpecifyNegativeMilliseconds() { UnixTime.ToDateTime(0, -1); }