public void GetModifiedDateAddDaySuccess() { var fromDate = DateTime.Parse("10/29/1979"); const DateFunction function = DateFunction.Add; var span = new DateSpan { Days = 1 }; var result = Calculator.GetModifiedDate(fromDate, function, span); Assert.AreEqual(30, result.Day); }
public void GetModifiedDateAddAllSuccess() { var fromDate = DateTime.Parse("10/29/1979"); const DateFunction function = DateFunction.Add; var span = new DateSpan { Years = 1, Months=1, Days=1 }; var result = Calculator.GetModifiedDate(fromDate, function, span); Assert.AreEqual(DateTime.Parse("11/30/1980").Date, result.Date); }
public static DateSpan CalculateDifference(DateTime firstDate, DateTime secondDate) { var years = CalculateYears(firstDate, secondDate); var months = CalculateMonths(firstDate, secondDate, years); var days = CalculateDays(firstDate, secondDate, years, months); var result = new DateSpan { Years = years, Months = months, Days = days }; return result; }
private void CalculateResultsForAddOrSubtractDate() { var fromDate = FromDate.Value; var function = Add.Checked ? DateFunction.Add : DateFunction.Subtract; var dateSpan = new DateSpan { Years = Convert.ToInt32(Years.Value), Months = Convert.ToInt32(Months.Value), Days = Convert.ToInt32(Days.Value) }; var result = Calculator.GetModifiedDate(fromDate, function, dateSpan); ResultedDate.Text = result.ToLongDateString(); }
private static DateTime SubtractFromDate(DateTime fromDate, DateSpan dateOffset) { return fromDate.AddDays(-dateOffset.Days).AddMonths(-dateOffset.Months).AddYears(-dateOffset.Years); }
public static DateTime GetModifiedDate(DateTime fromDate, DateFunction function, DateSpan dateOffset) { return function == DateFunction.Add ? AddToDate(fromDate, dateOffset) : SubtractFromDate(fromDate, dateOffset); }
public void GetModifiedDateSubtractYearSuccess() { var fromDate = DateTime.Parse("10/29/1979"); const DateFunction function = DateFunction.Subtract; var span = new DateSpan { Years = 1 }; var result = Calculator.GetModifiedDate(fromDate, function, span); Assert.AreEqual(1978, result.Year); }