AddYears() public method

public AddYears ( System.DateTime time, int years ) : System.DateTime
time System.DateTime
years int
return System.DateTime
コード例 #1
0
        private void VerificationHelper(DateTime value, int addValue)
        {
            System.Globalization.Calendar tc = new TaiwanCalendar();
            DateTime newDate = tc.AddYears(value, addValue);
            _errorNo++;
            Assert.Equal(newDate.Year, (value.Year + addValue));

            if (value.Month == 2)
            {
                if ((DateTime.IsLeapYear(value.Year) && value.Day == 29) || (!DateTime.IsLeapYear(value.Year) && value.Day == 28))
                {
                    if (DateTime.IsLeapYear(newDate.Year))
                    {
                        Assert.Equal(29, newDate.Day);
                    }
                    else
                    {
                        Assert.Equal(28, newDate.Day);
                    }
                }
            }
        }