public void RoundTripsAsExpectedWithOffset() { // Simulated value constructed with an offset. Either from previous versions of the library, or a manually constructed value var date = DATETIMETYPE.Parse("2019-02-20T10:36:51-08:00"); // DATETIMETYPE > string Assert.AreEqual("2019-02-20T10:36:51", date.ToString()); // DATETIMETYPE > string Assert.AreEqual("2019-02-20T10:36:51-08:00", date.ToString(true)); // DATETIMETYPE > string Assert.AreEqual("2019-02-20T10:36:51", date.ToString(false)); // DATETIMETYPE > string > DATETIMETYPE > string Assert.AreEqual("2019-02-20T10:36:51-08:00", DATETIMETYPE.Parse(date.ToString(true)).ToString(true)); // ********************************************************************************* // NOTE: // The rest of these tests convert to DateTime. We'll lose offset information. // That is OK as long as the time component does not change // ********************************************************************************* // DATETIMETYPE > DateTime > DATETIMETYPE > string Assert.AreEqual("2019-02-20T10:36:51", new DATETIMETYPE(date.ToDateTime()).ToString()); // DATETIMETYPE > DateTime > string > DATETIMETYPE > string Assert.AreEqual("2019-02-20T10:36:51", DATETIMETYPE.Parse(date.ToDateTime().ToString()).ToString()); // DATETIMETYPE > DateTime > string > DateTime > DATETIMETYPE > string Assert.AreEqual("2019-02-20T10:36:51", new DATETIMETYPE(DateTime.Parse(date.ToDateTime().ToString())).ToString()); }
public void ThrowsFormatExceptionWhenInvalidStringIsParsed(string dateString) { Assert.Throws <FormatException>(() => { var dt = DATETIMETYPE.Parse(dateString); }); }
public void ThrowsArgumentNullExceptionWhenNullStringIsParsed() { Assert.Throws <ArgumentNullException>(() => { var dt = DATETIMETYPE.Parse(null); }); }
public void ThrowsWhenParsedFromStringAfterQbEpoch() { Assert.Throws <ArgumentOutOfRangeException>(() => { var dt = DATETIMETYPE.Parse("2038-01-19T03:14:08+00:00"); }); }
public void DoesNotThrowWhenParsedFromStringOnQbEpoch() { Assert.DoesNotThrow(() => { var dt = DATETIMETYPE.Parse("2038-01-19T03:14:07+00:00"); }); }
public void MidnightIsAssumedIfTimeComponentMissing() { var dt = DATETIMETYPE.Parse("2019-02-06"); var date = dt.ToDateTime(); Assert.AreEqual("2019-02-06T00:00:00", dt.ToString()); Assert.AreEqual(new DateTime(2019, 2, 6, 0, 0, 0), date); }
private static DATETIMETYPE[] ToDateTimeIsUnspecifiedForNonZeroAndEmptyOffsetsInputs() { return(new[] { DATETIMETYPE.Parse("2019-02-06T17:24:00"), DATETIMETYPE.Parse("2019-02-07T17:24:00-08:00"), new DATETIMETYPE(new DateTime(2019, 1, 1, 8, 0, 0, 0, DateTimeKind.Unspecified)), DATETIMETYPE.FromUncorrectedDate(new DateTimeOffset(2019, 2, 9, 17, 24, 0, TimeSpan.FromHours(-8))) }); }
private static DATETIMETYPE[] ToDateTimeIsUtcForZeroOffsetsInput() { return(new[] { DATETIMETYPE.Parse("2019-02-06T17:24:00Z"), DATETIMETYPE.Parse("2019-02-06T17:24:00+00:00"), new DATETIMETYPE(new DateTime(2019, 1, 1, 8, 0, 0, 0, DateTimeKind.Utc)), DATETIMETYPE.FromUncorrectedDate(new DateTimeOffset(2019, 2, 6, 17, 24, 0, TimeSpan.Zero)), }); }
public void RoundTripsAsExpectedWithoutOffset() { // Simulated value returned from QuickBooks, that we want to be sent the exact same way to future queries var str = "2019-02-20T10:36:51"; var date = DATETIMETYPE.Parse(str); // DATETIMETYPE > string Assert.AreEqual(str, date.ToString()); // DATETIMETYPE > string > DATETIMETYPE > string Assert.AreEqual(str, DATETIMETYPE.Parse(date.ToString()).ToString()); // DATETIMETYPE > DateTime > DATETIMETYPE > string Assert.AreEqual(str, new DATETIMETYPE(date.ToDateTime()).ToString()); // DATETIMETYPE > DateTime > string > DATETIMETYPE > string Assert.AreEqual(str, DATETIMETYPE.Parse(date.ToDateTime().ToString()).ToString()); // DATETIMETYPE > DateTime > string > DateTime > DATETIMETYPE > string Assert.AreEqual(str, new DATETIMETYPE(DateTime.Parse(date.ToDateTime().ToString())).ToString()); // DATETIMETYPE > DateTime > Ticks > DateTime > DATETIMETYPE > string Assert.AreEqual(str, new DATETIMETYPE(new DateTime(date.ToDateTime().Ticks)).ToString()); }
public string ToStringOffsetExistenceMatchesInputWhenParsingFromStringWithOffset(string input) { return(DATETIMETYPE.Parse(input).ToString(true)); }