public void TestDateTime() { DateTime dt = new DateTime(1978, 4, 25, 7, 5, 10); RawTime rawTime = new RawTime(11, 12, 30, 100, true); initPOFWriter(); pofWriter.WriteDateTime(0, dt); pofWriter.WriteDateTime(0, new DateTime(1982, 11, 10, 12, 14, 20)); pofWriter.WriteDateTime(0, new DateTime(1999, 3, 4, 5, 6, 11, 110)); pofWriter.WriteDateTime(0, DateTime.MinValue); pofWriter.WriteDate(0, dt.Date); pofWriter.WriteRawTime(0, rawTime); initPOFReader(); Assert.AreEqual(dt, pofReader.ReadDateTime(0)); Assert.AreEqual(new DateTime(1982, 11, 10, 12, 14, 20), pofReader.ReadDateTime(0)); Assert.AreEqual(new DateTime(1999, 3, 4, 5, 6, 11, 110), pofReader.ReadDateTime(0)); Assert.AreEqual(DateTime.MinValue, pofReader.ReadDateTime(0)); DateTime result = pofReader.ReadDateTime(0); Assert.AreEqual(dt.Date, result.Date); Assert.AreEqual(new DateTime(1, 1, 1, rawTime.Hour, rawTime.Minute, rawTime.Second, rawTime.Nanosecond / 1000000), pofReader.ReadDateTime(0)); }
public void TestToUniversalTime() { RawTime timeUtc = new RawTime(15, 55, 0, 0, true); RawTime timeNoZone = new RawTime(15, 55, 0, 0, false); RawTime timeWithOffset = new RawTime(10, 55, 0, 0, -5, 0); DateTime dtUtc = timeUtc.ToUniversalTime(); Assert.AreEqual(timeUtc.Hour, dtUtc.Hour); Assert.AreEqual(timeUtc.Minute, dtUtc.Minute); Assert.AreEqual(timeUtc.Second, dtUtc.Second); Assert.AreEqual(timeUtc.Nanosecond, dtUtc.Millisecond * 1000000); Assert.AreEqual(DateTimeKind.Utc, dtUtc.Kind); dtUtc = timeNoZone.ToUniversalTime(); DateTime dt = new DateTime(1, 1, 1, timeNoZone.Hour, timeNoZone.Minute, timeNoZone.Second, timeNoZone.Nanosecond / 1000000); Assert.AreEqual(dt, dtUtc); Assert.AreEqual(DateTimeKind.Utc, dtUtc.Kind); dtUtc = timeWithOffset.ToUniversalTime(); dt = new DateTime(1, 1, 1, timeWithOffset.Hour, timeWithOffset.Minute, timeWithOffset.Second, timeWithOffset.Nanosecond / 1000000); dt = dt.Subtract(new TimeSpan(timeWithOffset.HourOffset, timeWithOffset.MinuteOffset, 0)); Assert.AreEqual(dt, dtUtc); Assert.AreEqual(DateTimeKind.Utc, dtUtc.Kind); }
public void TestToLocalTime() { RawTime timeUtc = new RawTime(15, 55, 0, 0, true); RawTime timeNoZone = new RawTime(15, 55, 0, 0, false); RawTime timeWithOffset = new RawTime(10, 55, 0, 0, -5, 0); DateTime dtLocal = timeUtc.ToLocalTime(); DateTime dt = new DateTime(1, 1, 1, timeUtc.Hour, timeUtc.Minute, timeUtc.Second, timeUtc.Nanosecond / 1000000); Assert.AreEqual(dt.ToLocalTime(), dtLocal); Assert.AreEqual(DateTimeKind.Local, dtLocal.Kind); dtLocal = timeNoZone.ToLocalTime(); dt = new DateTime(1, 1, 1, 15, 55, 0, 0); Assert.AreEqual(dt.ToLocalTime(), dtLocal); Assert.AreEqual(DateTimeKind.Local, dtLocal.Kind); dtLocal = timeWithOffset.ToLocalTime(); dt = new DateTime(1, 1, 1, timeWithOffset.Hour, timeWithOffset.Minute, timeWithOffset.Second, timeWithOffset.Nanosecond / 1000000); dt = dt.Subtract(new TimeSpan(timeWithOffset.HourOffset, timeWithOffset.MinuteOffset, 0)); Assert.AreEqual(dt.ToLocalTime(), dtLocal); Assert.AreEqual(DateTimeKind.Local, dtLocal.Kind); }
public void TestToDateTime() { RawTime timeUtc = new RawTime(15, 55, 0, 0, true); RawTime timeNoZone = new RawTime(15, 55, 0, 0, false); RawTime timeWithOffset = new RawTime(10, 55, 0, 0, -5, 0); DateTime dtUnspecified = timeUtc.ToDateTime(); DateTime dt = new DateTime(1, 1, 1, timeUtc.Hour, timeUtc.Minute, timeUtc.Second, timeUtc.Nanosecond / 1000000); Assert.AreEqual(dt, dtUnspecified); Assert.AreEqual(DateTimeKind.Unspecified, dtUnspecified.Kind); dtUnspecified = timeNoZone.ToDateTime(); dt = new DateTime(1, 1, 1, 15, 55, 0, 0); Assert.AreEqual(dt, dtUnspecified); Assert.AreEqual(DateTimeKind.Unspecified, dtUnspecified.Kind); dtUnspecified = timeWithOffset.ToDateTime(); dt = new DateTime(1, 1, 1, timeWithOffset.Hour, timeWithOffset.Minute, timeWithOffset.Second, timeWithOffset.Nanosecond / 1000000); Assert.AreEqual(dt, dtUnspecified); Assert.AreEqual(DateTimeKind.Unspecified, dtUnspecified.Kind); }
public void TestWriteTimeWithException() { RawTime t = new RawTime(7, 5, 10, 110, false); initPOFWriter(); stream.Close(); pofWriter.WriteRawTime(0, t); }
public void TestToString() { RawTime timeUtc = new RawTime(13, 2, 30, 0, true); RawTime time = new RawTime(13, 2, 30, 99, false); RawTime timeOffset = new RawTime(13, 2, 30, 0, -1, 30); Assert.IsTrue(timeUtc.ToString().StartsWith("13:02:30Z")); Assert.IsTrue(time.ToString().StartsWith("13:02:30.000000099")); Assert.IsTrue(timeOffset.ToString().StartsWith("13:02:30-01")); }
/// <summary> /// Construct a date-time value. /// </summary> /// <param name="date"> /// The date portion of the raw date-time value. /// </param> /// <param name="time"> /// The time portion of the raw date-time value. /// </param> public RawDateTime(DateTime date, RawTime time) { if (time == null) { throw new ArgumentNullException("time"); } m_date = date; m_time = time; }
public void TestEquals() { RawTime timeUtc = new RawTime(13, 2, 30, 0, true); RawTime time = new RawTime(13, 2, 30, 99, false); RawTime timeOffset = new RawTime(13, 2, 30, 0, -1, 30); Assert.IsTrue(time.Equals(time)); Assert.IsTrue(timeUtc.Equals(new RawTime(13, 2, 30, 0, true))); Assert.IsFalse(time.Equals(new RawTime(13, 2, 30, 99, true))); Assert.IsTrue(timeOffset.Equals(new RawTime(13, 2, 30, 0, -1, 30))); }
public void TestEquals() { DateTime date = new DateTime(1976, 4, 19); RawTime timeUtc = new RawTime(13, 2, 30, 0, true); RawTime time = new RawTime(13, 2, 30, 99, false); RawDateTime datetimeUtc = new RawDateTime(date, timeUtc); RawDateTime datetime = new RawDateTime(date, time); Assert.IsTrue(datetime.Equals(datetime)); Assert.IsFalse(datetime.Equals(datetimeUtc)); Assert.IsTrue(datetimeUtc.Equals(new RawDateTime(new DateTime(1976, 4, 19), new RawTime(13, 2, 30, 0, true)))); }
public void TestToUniversalTime() { DateTime date = new DateTime(1976, 4, 19); RawTime timeUtc = new RawTime(15, 55, 0, 0, true); RawTime timeNoZone = new RawTime(15, 55, 0, 0, false); RawTime timeWithOffset = new RawTime(10, 55, 0, 0, -5, 0); RawDateTime datetimeUtc = new RawDateTime(date, timeUtc); RawDateTime datetimeNoZone = new RawDateTime(date, timeNoZone); RawDateTime datetimeWithOffset = new RawDateTime(date, timeWithOffset); DateTime dtUtc = datetimeUtc.ToUniversalTime(); DateTime dt = new DateTime( datetimeUtc.Date.Year, datetimeUtc.Date.Month, datetimeUtc.Date.Day, datetimeUtc.Time.Hour, datetimeUtc.Time.Minute, datetimeUtc.Time.Second, datetimeUtc.Time.Nanosecond / 1000000); Assert.AreEqual(dt, dtUtc); Assert.AreEqual(DateTimeKind.Utc, dtUtc.Kind); dtUtc = datetimeNoZone.ToUniversalTime(); dt = new DateTime( datetimeNoZone.Date.Year, datetimeNoZone.Date.Month, datetimeNoZone.Date.Day, datetimeNoZone.Time.Hour, datetimeNoZone.Time.Minute, datetimeNoZone.Time.Second, datetimeNoZone.Time.Nanosecond / 1000000); Assert.AreEqual(dt, dtUtc); Assert.AreEqual(DateTimeKind.Utc, dtUtc.Kind); dtUtc = datetimeWithOffset.ToUniversalTime(); dt = new DateTime( datetimeWithOffset.Date.Year, datetimeWithOffset.Date.Month, datetimeWithOffset.Date.Day, datetimeWithOffset.Time.Hour, datetimeWithOffset.Time.Minute, datetimeWithOffset.Time.Second, datetimeWithOffset.Time.Nanosecond / 1000000); dt = dt.Subtract(new TimeSpan(datetimeWithOffset.Time.HourOffset, datetimeWithOffset.Time.MinuteOffset, 0)); Assert.AreEqual(dt, dtUtc); Assert.AreEqual(DateTimeKind.Utc, dtUtc.Kind); }
public void TestToDateTime() { DateTime date = new DateTime(1976, 4, 19); RawTime timeUtc = new RawTime(15, 55, 0, 0, true); RawTime timeNoZone = new RawTime(15, 55, 0, 0, false); RawTime timeWithOffset = new RawTime(10, 55, 0, 0, -5, 0); RawDateTime datetimeUtc = new RawDateTime(date, timeUtc); RawDateTime datetimeNoZone = new RawDateTime(date, timeNoZone); RawDateTime datetimeWithOffset = new RawDateTime(date, timeWithOffset); DateTime dtUnspecified = datetimeUtc.ToDateTime(); DateTime dt = new DateTime( datetimeUtc.Date.Year, datetimeUtc.Date.Month, datetimeUtc.Date.Day, datetimeUtc.Time.Hour, datetimeUtc.Time.Minute, datetimeUtc.Time.Second, datetimeUtc.Time.Nanosecond / 1000000); Assert.AreEqual(dt, dtUnspecified); Assert.AreEqual(DateTimeKind.Unspecified, dtUnspecified.Kind); dtUnspecified = datetimeNoZone.ToDateTime(); dt = new DateTime( datetimeNoZone.Date.Year, datetimeNoZone.Date.Month, datetimeNoZone.Date.Day, datetimeNoZone.Time.Hour, datetimeNoZone.Time.Minute, datetimeNoZone.Time.Second, datetimeNoZone.Time.Nanosecond / 1000000); Assert.AreEqual(dt, dtUnspecified); Assert.AreEqual(DateTimeKind.Unspecified, dtUnspecified.Kind); dtUnspecified = datetimeWithOffset.ToDateTime(); dt = new DateTime( datetimeWithOffset.Date.Year, datetimeWithOffset.Date.Month, datetimeWithOffset.Date.Day, datetimeWithOffset.Time.Hour, datetimeWithOffset.Time.Minute, datetimeWithOffset.Time.Second, datetimeWithOffset.Time.Nanosecond / 1000000); Assert.AreEqual(dt, dtUnspecified); Assert.AreEqual(DateTimeKind.Unspecified, dtUnspecified.Kind); }
public void TestToString() { DateTime date = new DateTime(1976, 4, 19); RawTime timeUtc = new RawTime(13, 2, 30, 0, true); RawTime time = new RawTime(13, 2, 30, 99, false); RawTime timeOffset = new RawTime(13, 2, 30, 0, -1, 30); RawDateTime datetimeUtc = new RawDateTime(date, timeUtc); RawDateTime datetime = new RawDateTime(date, time); RawDateTime datetimeOffset = new RawDateTime(date, timeOffset); Assert.IsTrue(datetime.ToString().StartsWith(PofHelper.FormatDate(1976, 4, 19))); Assert.IsTrue(datetimeUtc.ToString().EndsWith("13:02:30Z")); Assert.IsTrue(datetime.ToString().EndsWith("13:02:30.000000099")); Assert.IsTrue(datetimeOffset.ToString().EndsWith("13:02:30-01:30")); }
public void TestRawTime() { RawTime timeUtc = new RawTime(15, 55, 0, 0, true); RawTime timeNoZone = new RawTime(15, 55, 0, 0, false); RawTime timeWithOffset = new RawTime(10, 55, 0, 0, -5, 0); initPOFWriter(); pofWriter.WriteRawTime(0, timeUtc); pofWriter.WriteRawTime(0, timeNoZone); pofWriter.WriteRawTime(0, timeWithOffset); initPOFReader(); Assert.AreEqual(timeUtc, pofReader.ReadRawTime(0)); Assert.AreEqual(timeNoZone, pofReader.ReadRawTime(0)); Assert.AreEqual(timeWithOffset, pofReader.ReadRawTime(0)); }
/// <summary> /// Compare this object with another for equality. /// </summary> /// <param name="o"> /// Another object to compare to for equality. /// </param> /// <returns> /// <b>true</b> iff this object is equal to the other object. /// </returns> public override bool Equals(object o) { if (o is RawTime) { RawTime that = (RawTime)o; return(this == that || Hour == that.Hour && Minute == that.Minute && Second == that.Second && Nanosecond == that.Nanosecond && IsUtc == that.IsUtc && HourOffset == that.HourOffset && MinuteOffset == that.MinuteOffset); } return(false); }
public void TestRawDateTime() { DateTime date = new DateTime(1976, 4, 19); RawTime timeUtc = new RawTime(15, 55, 0, 0, true); RawTime timeNoZone = new RawTime(15, 55, 0, 0, false); RawTime timeWithOffset = new RawTime(10, 55, 0, 0, -5, 0); RawDateTime datetimeUtc = new RawDateTime(date, timeUtc); RawDateTime datetimeNoZone = new RawDateTime(date, timeNoZone); RawDateTime datetimeWithOffset = new RawDateTime(date, timeWithOffset); initPOFWriter(); pofWriter.WriteDate(0, date); pofWriter.WriteRawDateTime(0, datetimeUtc); pofWriter.WriteRawDateTime(0, datetimeNoZone); pofWriter.WriteRawDateTime(0, datetimeWithOffset); initPOFReader(); Assert.AreEqual(date, pofReader.ReadRawDateTime(0).Date); Assert.AreEqual(datetimeUtc, pofReader.ReadRawDateTime(0)); Assert.AreEqual(datetimeNoZone, pofReader.ReadRawDateTime(0)); Assert.AreEqual(datetimeWithOffset, pofReader.ReadRawDateTime(0)); }
public void TestObject() { initPOFWriter(); // 1 pofWriter.WriteObject(0, null); pofWriter.WriteObject(0, false); pofWriter.WriteBoolean(0, true); pofWriter.WriteBoolean(0, false); pofWriter.WriteObject(0, 'a'); pofWriter.WriteObject(0, Byte.MinValue); pofWriter.WriteObject(0, Int16.MaxValue); pofWriter.WriteObject(0, 0); pofWriter.WriteObject(0, -1); pofWriter.WriteObject(0, Int32.MaxValue); // 11 pofWriter.WriteObject(0, (Int64)(-1)); pofWriter.WriteObject(0, Int64.MinValue); pofWriter.WriteObject(0, (Single)0); pofWriter.WriteObject(0, Single.NaN); pofWriter.WriteObject(0, Single.NegativeInfinity); pofWriter.WriteObject(0, Double.NaN); pofWriter.WriteObject(0, "test "); pofWriter.WriteObject(0, String.Empty); pofWriter.WriteObject(0, new DateTime(1978, 4, 25, 7, 5, 10, 110)); DateTime dtUtc = new DateTime(2006, 8, 18, 11, 28, 10, 100, DateTimeKind.Utc); RawTime rawTime1 = new RawTime(11, 30, 0, 99, true); RawTime rawTime2 = new RawTime(11, 30, 0, 99, 2, 30); pofWriter.WriteObject(0, dtUtc); // 21 pofWriter.WriteObject(0, rawTime1); pofWriter.WriteObject(0, rawTime2); bool[] bArray = new bool[] { true, true }; pofWriter.WriteObject(0, bArray); byte[] byteArray = new byte[] { 1, 2, 3 }; pofWriter.WriteObject(0, byteArray); char[] charArray = new char[] { 'a', 'd', Char.MinValue }; pofWriter.WriteObject(0, charArray); Int16[] i16Array = new Int16[] { 100, 200, Int16.MinValue }; pofWriter.WriteObject(0, i16Array); Int32[] i32Array = new Int32[] { 100, 200, Int32.MinValue }; pofWriter.WriteObject(0, i32Array); Int64[] i64Array = new Int64[] { 100, 200, Int64.MinValue }; pofWriter.WriteObject(0, i64Array); ArrayList al = new ArrayList(); al.Add(true); al.Add(5); pofWriter.WriteObject(0, al); Single[] fArray = new Single[] { Single.MinValue, Single.NegativeInfinity }; pofWriter.WriteObject(0, fArray); Double[] dArray = new Double[] { Double.MinValue, Double.NegativeInfinity }; pofWriter.WriteObject(0, dArray); object[] objArray = new object[] { true, Double.NaN }; // 31 pofWriter.WriteObject(0, objArray); RawYearMonthInterval ymi = new RawYearMonthInterval(10, 6); pofWriter.WriteObject(0, ymi); TimeSpan ts = new TimeSpan(1, 16, 30, 25, 400); pofWriter.WriteObject(0, ts); TimeSpan ts1 = new TimeSpan(5, 10, 30); pofWriter.WriteObject(0, ts1); initPOFReader(); // 1 Assert.AreEqual(null, pofReader.ReadObject(0)); Assert.AreEqual(false, pofReader.ReadObject(0)); Assert.AreEqual(true, pofReader.ReadObject(0)); Assert.AreEqual(false, pofReader.ReadObject(0)); Assert.AreEqual('a', pofReader.ReadObject(0)); Assert.AreEqual(Byte.MinValue, pofReader.ReadObject(0)); Assert.AreEqual(Int16.MaxValue, pofReader.ReadObject(0)); Assert.AreEqual(0, pofReader.ReadObject(0)); Assert.AreEqual(-1, pofReader.ReadObject(0)); Assert.AreEqual(Int32.MaxValue, pofReader.ReadObject(0)); // 11 Assert.AreEqual(-1, pofReader.ReadObject(0)); Assert.AreEqual(Int64.MinValue, pofReader.ReadObject(0)); Assert.AreEqual(0, pofReader.ReadObject(0)); Assert.AreEqual(Single.NaN, pofReader.ReadObject(0)); Assert.AreEqual(Single.NegativeInfinity, pofReader.ReadObject(0)); Assert.AreEqual(Double.NaN, pofReader.ReadObject(0)); Assert.AreEqual("test ", pofReader.ReadObject(0)); Assert.AreEqual(String.Empty, pofReader.ReadObject(0)); Assert.AreEqual(new DateTime(1978, 4, 25, 7, 5, 10, 110), pofReader.ReadObject(0)); Assert.AreEqual(dtUtc, pofReader.ReadObject(0)); // 21 Assert.AreEqual(rawTime1, pofReader.ReadObject(0)); Assert.AreEqual(rawTime2, pofReader.ReadObject(0)); Assert.AreEqual(bArray, pofReader.ReadObject(0)); Assert.AreEqual(byteArray, pofReader.ReadObject(0)); Assert.AreEqual(charArray, pofReader.ReadObject(0)); Assert.AreEqual(i16Array, pofReader.ReadObject(0)); Assert.AreEqual(i32Array, pofReader.ReadObject(0)); Assert.AreEqual(i64Array, pofReader.ReadObject(0)); Object result = pofReader.ReadObject(0); Assert.IsTrue(result is ICollection); ArrayList ares = new ArrayList((ICollection)result); Assert.AreEqual(ares[0], al[0]); Assert.AreEqual(ares[1], al[1]); Assert.AreEqual(fArray, pofReader.ReadObject(0)); Assert.AreEqual(dArray, pofReader.ReadObject(0)); // 31 Assert.AreEqual(objArray, pofReader.ReadObject(0)); Assert.AreEqual(ymi, pofReader.ReadObject(0)); Assert.AreEqual(ts, pofReader.ReadObject(0)); Assert.AreEqual(ts1, pofReader.ReadObject(0)); }