コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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();
        }
コード例 #5
0
 private static DateTime SubtractFromDate(DateTime fromDate, DateSpan dateOffset)
 {
     return fromDate.AddDays(-dateOffset.Days).AddMonths(-dateOffset.Months).AddYears(-dateOffset.Years);
 }
コード例 #6
0
 public static DateTime GetModifiedDate(DateTime fromDate, DateFunction function, DateSpan dateOffset)
 {
     return function == DateFunction.Add ? AddToDate(fromDate, dateOffset) : SubtractFromDate(fromDate, dateOffset);
 }
コード例 #7
0
        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);
        }