/// <summary>返回与指定 <see cref="T:System.DateTime" /> 相距指定年数的 <see cref="T:System.DateTime" />。</summary>
/// <returns>将指定年数添加到指定的 <see cref="T:System.DateTime" /> 中时得到的 <see cref="T:System.DateTime" />。</returns>
/// <param name="time">
/// <see cref="T:System.DateTime" />,将向其添加 <paramref name="years" />。</param>
/// <param name="years">要添加的年数。</param>
/// <exception cref="T:System.ArgumentException">结果 <see cref="T:System.DateTime" /> 超出了支持的范围。</exception>
public override DateTime AddYears(DateTime time, int years)
{
int datePart = this.GetDatePart(time.Ticks, 0);
int month = this.GetDatePart(time.Ticks, 2);
int day = this.GetDatePart(time.Ticks, 3);
int num = datePart + years;
HebrewCalendar.CheckHebrewYearValue(num, 0, "years");
int monthsInYear = this.GetMonthsInYear(num, 0);
if (month > monthsInYear)
{
month = monthsInYear;
}
int daysInMonth = this.GetDaysInMonth(num, month);
if (day > daysInMonth)
{
day = daysInMonth;
}
long ticks = this.ToDateTime(num, month, day, 0, 0, 0, 0).Ticks + time.Ticks % 864000000000L;
DateTime supportedDateTime1 = this.MinSupportedDateTime;
DateTime supportedDateTime2 = this.MaxSupportedDateTime;
Calendar.CheckAddResult(ticks, supportedDateTime1, supportedDateTime2);
return(new DateTime(ticks));
}