The type of units to add ("years" or "months").
The number of months or years to add to this DateTime.
Whether the days should be allowed to overflow, causing the month to increment.
A reference to the DateTime (this).
auto dt1 = DateTime(2010, 1, 1, 12, 33, 33); dt1.roll!"months"(1); assert(dt1 == DateTime(2010, 2, 1, 12, 33, 33)); auto dt2 = DateTime(2010, 1, 1, 12, 33, 33); dt2.roll!"months"(-1); assert(dt2 == DateTime(2010, 12, 1, 12, 33, 33)); auto dt3 = DateTime(1999, 1, 29, 12, 33, 33); dt3.roll!"months"(1); assert(dt3 == DateTime(1999, 3, 1, 12, 33, 33)); auto dt4 = DateTime(1999, 1, 29, 12, 33, 33); dt4.roll!"months"(1, AllowDayOverflow.no); assert(dt4 == DateTime(1999, 2, 28, 12, 33, 33)); auto dt5 = DateTime(2000, 2, 29, 12, 30, 33); dt5.roll!"years"(1); assert(dt5 == DateTime(2001, 3, 1, 12, 30, 33)); auto dt6 = DateTime(2000, 2, 29, 12, 30, 33); dt6.roll!"years"(1, AllowDayOverflow.no); assert(dt6 == DateTime(2001, 2, 28, 12, 30, 33));
Adds the given number of years or months to this DateTime, mutating it. A negative number will subtract.
The difference between rolling and adding is that rolling does not affect larger units. Rolling a DateTime 12 months gets the exact same DateTime. However, the days can still be affected due to the differing number of days in each month.
Because there are no units larger than years, there is no difference between adding and rolling years.