std.datetime.date.roll - multiple declarations
- Function Date.roll
- Function Date.roll
Function Date.roll
Adds the given number of units to this Date. A negative number will
subtract.
The difference between rolling and adding is that rolling does not
affect larger units. For instance, rolling a Date one
year's worth of days gets the exact same Date.
The only accepted units are ".
days"
Prototype
ref Date roll(string units)( long days ) pure nothrow @safe if (units == "days");
Parameters
| Name | Description |
|---|---|
| units | The units to add. Must be ". |
| days | The number of days to add to this Date. |
Example
auto d = Date(2010, 1, 1); d.roll!"days"(1); assert(d == Date(2010, 1, 2)); d.roll!"days"(365); assert(d == Date(2010, 1, 26)); d.roll!"days"(-32); assert(d == Date(2010, 1, 25));
Function Date.roll
Adds the given number of years or months to this Date. A negative
number will subtract.
The difference between rolling and adding is that rolling does not
affect larger units. Rolling a Date 12 months gets
the exact same Date. 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.
Prototype
ref Date roll(string units)( long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes ) pure nothrow @safe if (units == "years");
Parameters
| Name | Description |
|---|---|
| units | The type of units to add ("years" or "months"). |
| value | The number of months or years to add to this
Date. |
| allowOverflow | Whether the day should be allowed to overflow,
causing the month to increment. |
Example
auto d1 = Date(2010, 1, 1); d1.roll!"months"(1); assert(d1 == Date(2010, 2, 1)); auto d2 = Date(2010, 1, 1); d2.roll!"months"(-1); assert(d2 == Date(2010, 12, 1)); auto d3 = Date(1999, 1, 29); d3.roll!"months"(1); assert(d3 == Date(1999, 3, 1)); auto d4 = Date(1999, 1, 29); d4.roll!"months"(1, AllowDayOverflow.no); assert(d4 == Date(1999, 2, 28)); auto d5 = Date(2000, 2, 29); d5.roll!"years"(1); assert(d5 == Date(2001, 3, 1)); auto d6 = Date(2000, 2, 29); d6.roll!"years"(1, AllowDayOverflow.no); assert(d6 == Date(2001, 2, 28));
Authors
Jonathan M Davis and Kato Shoichi