The OpenD Programming Language

Interval.shift

Shifts the 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 both begin and end. It effectively calls add!"years"() and then add!"months"() on begin and end with the given number of years and months.

  1. void shift(D duration)
  2. void shift(T years, T months, AllowDayOverflow allowOverflow)
    struct Interval(TP)
    static if(__traits(compiles, begin.add!"months"(1)) && __traits(compiles, begin.add!"years"(1)))
    void
    shift
    (
    T
    )

Parameters

years T

The number of years to shift the interval by.

months T

The number of months to shift the interval by.

allowOverflow AllowDayOverflow

Whether the days should be allowed to overflow on begin and end, causing their month to increment.

Throws

std.datetime.date.DateTimeException if this interval is empty or if the resulting interval would be invalid.

Examples

auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));

interval1.shift(2);
assert(interval1 == Interval!Date(Date(1998, 1, 2), Date(2014, 3, 1)));

interval2.shift(-2);
assert(interval2 == Interval!Date(Date(1994, 1, 2), Date(2010, 3, 1)));

Meta