public void DateTimeWithHoursMinutesAndSeconds_10DaysBefore_Returns10DaysBeforeGivenDate() { var givenDate = new DateTime(2012, 12, 13, 1, 2, 3); var timeSpanTenDays = new TimeSpan(10, 0, 0, 0); DateTime actual = timeSpanTenDays.Before(givenDate); var expected = new DateTime(2012, 12, 3, 1, 2, 3); Assert.Equal(expected, actual); }
/// <summary> /// Subtracts given <see cref="TimeSpan"/> from <paramref name="originalValue"/> <see cref="DateTime"/> and returns resulting <see cref="DateTime"/> in the past. /// </summary> public static DateTime Ago(this TimeSpan from, DateTime originalValue) { return(from.Before(originalValue)); }
/// <summary> /// Subtracts given <see cref="TimeSpan"/> from current date (<see cref="DateTime.Now"/>) and returns resulting <see cref="DateTime"/> in the past. /// </summary> public static DateTime Ago(this TimeSpan from) { return(from.Before(DateTime.Now)); }