public void ToDateTimeIsARoundTripOperationExceptForLossOfPrecision_Utc() { DateTime now = new DateTime(1999, 12, 31, 0, 0, 0, DateTimeKind.Utc); ASDate date = new ASDate(now); Assert.AreEqual(now, date.ToDateTime()); }
/// <inheritdoc /> public override bool Equals(object obj) { ASDate other = obj as ASDate; return(other != null && other.millisecondsSinceEpoch == millisecondsSinceEpoch && other.timeZoneOffsetMinutes == timeZoneOffsetMinutes); }
public void ConstructorWithMillisAndTimeZoneOffset() { ASDate asDate = new ASDate(123.0, 456); Assert.AreEqual(123.0, asDate.MillisecondsSinceEpoch); Assert.AreEqual(456, asDate.TimeZoneOffsetMinutes); }
public void ConstructorWithDateTimeAndTimeZoneOffset() { DateTime then = new DateTime(1970, 1, 2, 0, 0, 0, DateTimeKind.Local); ASDate asDate = new ASDate(then, -600); Assert.AreEqual(86400000.0, asDate.MillisecondsSinceEpoch); Assert.AreEqual(-600, asDate.TimeZoneOffsetMinutes); }
public void ConstructorWithDateTime_NonUtc() { DateTime then = new DateTime(1970, 1, 2, 0, 0, 0, DateTimeKind.Local); ASDate asDate = new ASDate(then); int tzOffset = (int) TimeZone.CurrentTimeZone.GetUtcOffset(then).TotalMinutes; Assert.AreEqual(86400000.0 + tzOffset * 60000, asDate.MillisecondsSinceEpoch); Assert.AreEqual(tzOffset, asDate.TimeZoneOffsetMinutes); }
public void EqualsWithOtherDate(double millis1, int tzoffset1, double millis2, int tzoffset2, bool expectedResult) { ASDate date1 = new ASDate(millis1, tzoffset1); ASDate date2 = new ASDate(millis2, tzoffset2); Assert.AreEqual(expectedResult, date1.Equals(date2)); }
public void EqualsWithNonDateIsFalse() { ASDate date = new ASDate(DateTime.Now); Assert.AreNotEqual(date, 42); }
public void EqualsWithNullIsFalse() { ASDate date = new ASDate(DateTime.Now); Assert.AreNotEqual(date, null); }
public void GetHashCodeIsSane() { ASDate date1 = new ASDate(12.0, 120); ASDate date2 = new ASDate(12.0, 120); Assert.AreEqual(date1.GetHashCode(), date2.GetHashCode()); }
public void WriteObject_Objects_ReferenceCaching(AMFObjectEncoding objectEncoding, byte[] expected) { // Create an array with multiple copies of each kind of object and including a self-reference ASObject obj = new ASObject(); ASByteArray byteArray = new ASByteArray(new byte[0]); ASDate date = new ASDate(1, 0); ASArray array = new ASArray(6); array.IndexedValues[0] = obj; array.IndexedValues[1] = byteArray; array.IndexedValues[2] = date; array.IndexedValues[3] = obj; array.IndexedValues[4] = byteArray; array.IndexedValues[5] = date; array.DynamicProperties["a"] = array; output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(array); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Dates(AMFObjectEncoding objectEncoding, byte[] expected, int millisecondsSinceEpoch) { ASDate date = new ASDate(1, 0); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(date); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
private IASValue ReadDate() { int bits = input.ReadVWInt29(); // Handle cached objects. if ((bits & 1) == 0) { int referenceId = bits >> 1; return GetObjectFromCache(AMF3ObjectTypeCode.Date, referenceId); } // Read out the whole date. double millisecondsSinceEpoch = input.ReadDouble(); ASDate result = new ASDate(millisecondsSinceEpoch, 0); AddObjectToCache(AMF3ObjectTypeCode.Date, result); return result; }