public void ObjectOverrides() { // ToString var dt = new FudgeDateTime(2003, 11, 13, 12, 14, 34, 987654321, 0, FudgeDateTimePrecision.Nanosecond); Assert.Equal("2003-11-13T12:14:34.987654321+00:00", dt.ToString()); // Equals var dt2 = new FudgeDateTime(2003, 11, 13, 12, 14, 34, 987654321, 0, FudgeDateTimePrecision.Nanosecond); var dt3 = new FudgeDateTime(2003, 11, 13, 12, 14, 34, 987654321, 0, FudgeDateTimePrecision.Nanosecond); Assert.Equal(dt2, dt3); Assert.False(dt2.Equals(null)); Assert.False(dt2.Equals("Fred")); }
public void ConvertingToNativeTypes() { Assert.Throws<ArgumentOutOfRangeException>(() => new FudgeDateTime(new FudgeDate(-12300101), null).ToDateTime()); DateTime dt1 = new FudgeDateTime(1900, 2, 28, 12, 7, 34, 0, FudgeDateTimePrecision.Nanosecond).ToDateTime(); Assert.Equal("1900-02-28T12:07:34.0000000", dt1.ToString("o")); Assert.Equal(DateTimeKind.Unspecified, dt1.Kind); DateTime dt2 = new FudgeDateTime(1900, 2, 28, 12, 7, 34, 0, 60, FudgeDateTimePrecision.Nanosecond).ToDateTime(); Assert.Equal("1900-02-28T11:07:34.0000000Z", dt2.ToString("o")); // Back an hour Assert.Equal(DateTimeKind.Utc, dt2.Kind); DateTime dt3 = new FudgeDateTime(2009, 7, 13, 12, 0, 0, 0, FudgeDateTimePrecision.Nanosecond).ToDateTime(DateTimeKind.Local, true); Assert.Equal(DateTimeKind.Local, dt3.Kind); Assert.Equal(new DateTime(2009, 7, 13, 12, 0, 0, DateTimeKind.Utc).ToLocalTime(), dt3); DateTime dt4 = new FudgeDateTime(1900, 2, 28, 12, 7, 34, 0, 60, FudgeDateTimePrecision.Nanosecond).ToDateTime(DateTimeKind.Unspecified, false); Assert.Equal("1900-02-28T12:07:34.0000000", dt4.ToString("o")); // Ignore the offset because we're going to unspecified Assert.Equal(DateTimeKind.Unspecified, dt4.Kind); DateTimeOffset dto = new FudgeDateTime(1900, 2, 28, 12, 7, 34, 0, 60, FudgeDateTimePrecision.Nanosecond).ToDateTimeOffset(); Assert.Equal("1900-02-28T12:07:34.0000000+01:00", dto.ToString("o")); }