public void TryParseDate_nullableDate() { var date1 = UtcDate; var date2 = UtcDate.AddDays(DateInterval); var date3 = UtcDate.AddMonths(DateInterval); DateTime?date1Nullable = UtcDate; DateTime?date2Nullable = UtcDate.AddDays(DateInterval); DateTime?date3Nullable = UtcDate.AddMonths(DateInterval); Assert.AreEqual(date1.ToString("g"), date1Nullable.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Nullable.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Nullable.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), ((DateTime?)null).TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1Nullable.TryParseDate(date1).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Nullable.TryParseDate(date2).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Nullable.TryParseDate(date3).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), ((DateTime?)null).TryParseDate(date1).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), ((DateTime?)null).TryParseDate(date2).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), ((DateTime?)null).TryParseDate(date3).ToUtc().ToString("g")); }
public void TryParseDate_string() { var date1 = UtcDate; var date2 = UtcDate.AddDays(DateInterval); var date3 = UtcDate.AddMonths(DateInterval); var date4 = LocalDate; var date1Str = date1.ToString("g"); var date2Str = date2.ToString("g"); var date3Str = date3.ToString("g"); var date4Str = date4.ToString("O"); #region string date Assert.AreEqual(date1.ToString("g"), date1Str.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Str.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Str.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date4.ToString("g"), date4Str.TryParseDate().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), date4Str.TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date4.ToString("g"), date4Str.TryParseDate().ToTimezoneDate(LocalTimeZoneName).ToString("g")); Assert.AreEqual(date1.ToString("g"), "".TryParseDate().ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1Str.TryParseDate(date1).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Str.TryParseDate(date2).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Str.TryParseDate(date3).ToUtc().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), date4Str.TryParseDate(date4).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), "".TryParseDate(date1).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), "".TryParseDate(date2).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), "".TryParseDate(date3).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1Str.TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Str.TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Str.TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), date4Str.TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), "".TryParseDate(Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1Str.TryParseDate(date1, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2Str.TryParseDate(date2, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3Str.TryParseDate(date3, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), date4Str.TryParseDate(date4, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date1.ToString("g"), "".TryParseDate(date1, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date2.ToString("g"), "".TryParseDate(date2, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date3.ToString("g"), "".TryParseDate(date3, Culture, DateTimeStyles).ToUtc().ToString("g")); Assert.AreEqual(date4.ToUtc().ToString("g"), "".TryParseDate(date4, Culture, DateTimeStyles).ToUtc().ToString("g")); #endregion #region OADate Assert.AreEqual(date1.ToString("g"), date1.ToOADate().ToString(Culture).TryParseDate().ToString("g")); Assert.AreEqual(date2.ToString("g"), date2.ToOADate().ToString(Culture).TryParseDate().ToString("g")); Assert.AreEqual(date3.ToString("g"), date3.ToOADate().ToString(Culture).TryParseDate().ToString("g")); Assert.AreEqual(date1.ToString("g"), date1.ToOADate().ToString(Culture).TryParseDate(date1).ToString("g")); Assert.AreEqual(date2.ToString("g"), date2.ToOADate().ToString(Culture).TryParseDate(date2).ToString("g")); Assert.AreEqual(date3.ToString("g"), date3.ToOADate().ToString(Culture).TryParseDate(date3).ToString("g")); Assert.AreEqual(date1.ToString("g"), date1.ToOADate().ToString(Culture).TryParseDate(Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date2.ToString("g"), date2.ToOADate().ToString(Culture).TryParseDate(Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date3.ToString("g"), date3.ToOADate().ToString(Culture).TryParseDate(Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date1.ToString("g"), date1.ToOADate().ToString(Culture).TryParseDate(date1, Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date2.ToString("g"), date2.ToOADate().ToString(Culture).TryParseDate(date2, Culture, DateTimeStyles).ToString("g")); Assert.AreEqual(date3.ToString("g"), date3.ToOADate().ToString(Culture).TryParseDate(date3, Culture, DateTimeStyles).ToString("g")); #endregion }