std.datetime.interval.PosInfInterval.shift
- multiple declarations
Function PosInfInterval.shift
Shifts the begin
of this interval forward or backwards in time by
the given duration (a positive duration shifts the interval forward; a
negative duration shifts it backward). Effectively, it does
begin += duration
.
void shift(D)
(
D duration
) pure nothrow
if (__traits(compiles, begin + duration));
Parameters
Name | Description |
---|---|
duration | The duration to shift the interval by. |
Example
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1 .shift(dur!"days"(50));
assert(interval1 == PosInfInterval!Date(Date(1996, 2, 21)));
interval2 .shift(dur!"days"(-50));
assert(interval2 == PosInfInterval!Date(Date(1995, 11, 13)));
Function PosInfInterval.shift
Shifts the begin
of this interval forward or backwards in time
by the given number of years and/or months (a positive number of
years and months shifts the interval forward; a negative number
shifts it backward). It adds the years the given years and months to
begin
. It effectively calls add!"years"()
and then
add!"months"()
on begin
with the given number of years and
months.
void shift(T)
(
T years,
T months = 0,
AllowDayOverflow allowOverflow = AllowDayOverflow .yes
)
if (isIntegral!T);
Parameters
Name | Description |
---|---|
years | The number of years to shift the interval by. |
months | The number of months to shift the interval by. |
allowOverflow | Whether the days should be allowed to overflow
on begin , causing its month to increment. |
Throws
DateTimeException
if this interval is
empty or if the resulting interval would be invalid.
Example
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2));
auto interval2 = PosInfInterval!Date(Date(1996, 1, 2));
interval1 .shift(dur!"days"(50));
assert(interval1 == PosInfInterval!Date(Date(1996, 2, 21)));
interval2 .shift(dur!"days"(-50));
assert(interval2 == PosInfInterval!Date(Date(1995, 11, 13)));