Click or drag to resize

DayPlusYears Method

Returns the Day that comes the specified numberOfYears after this Day in the calendar.

Namespace: DegreeDays.Time
Assembly: DegreeDays (in DegreeDays.dll) Version: 1.4
Syntax
public Day PlusYears(
	int numberOfYears
)

Parameters

numberOfYears  Int32
The number of years to add to this Day. Can be positive (to go forwards in time), zero, or negative (to go backwards in time).

Return Value

Day
A Day representing the result of the operation.
Exceptions
ExceptionCondition
OverflowExceptionIn the unlikely event of this method requiring a Day with a year less than 1 or greater than 9999.
Remarks

This will always return a valid Day, unless it is outside the range allowed by Day (0001-01-01 to 9999-12-31 inclusive), in which case it will throw an OverflowException.

The MonthOfYear of the returned Day will always be the same as that of this Day. However, the DayOfMonth of the returned Day will change if this Day represents February 29th (in a leap year), and the resulting Day does not fall in a leap year. In this unusual situation the DayOfMonth of the returned Day will be 28 instead of 29, to ensure that it represents a valid date on the Gregorian calendar. For example:

  • 2016-02-29 plus 1 year would give a result of 2017-02-28 (because 2017 is not a leap year like 2016 is).
  • 2016-02-29 plus 4 years would give a result of 2020-02-29 (because 2020 is a leap year, like 2016).

Day is immutable, so calling this method will not change this Day.

See Also