The OpenD Programming Language

Interval.shift

Shifts the 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 and end += duration.

  1. void shift(D duration)
    struct Interval(TP)
    pure
    void
    shift
    (
    D
    )
    if (
    __traits(compiles, begin + duration)
    )
  2. void shift(T years, T months, AllowDayOverflow allowOverflow)

Parameters

duration D

The duration to shift the interval by.

Throws

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

Examples

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

interval1.shift(dur!"days"(50));
assert(interval1 == Interval!Date(Date(1996, 2, 21), Date(2012, 5, 25)));

interval2.shift(dur!"days"(-50));
assert(interval2 == Interval!Date(Date(1995, 11, 13), Date(2012, 2, 15)));

Meta