View source code
Display the source code in std/datetime/interval.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.datetime.interval.Interval.expand - multiple declarations

Function Interval.expand

Expands the interval forwards and/or backwards in time. Effectively, it does begin -= duration and/or end += duration. Whether it expands forwards and/or backwards in time is determined by dir.

void expand(D) (
  D duration,
  Direction dir = Direction.both
) pure
if (__traits(compiles, begin + duration));

Parameters

NameDescription
duration The duration to expand the interval by.
dir The direction in time to expand the interval.

Throws

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

Example

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.expand(2);
assert(interval1 == Interval!Date(Date(1994, 1, 2), Date(2014, 3, 1)));

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

Function Interval.expand

Expands the interval forwards and/or backwards in time. Effectively, it subtracts the given number of months/years from begin and adds them to end. Whether it expands forwards and/or backwards in time is determined by dir.

void expand(T) (
  T years,
  T months = 0,
  AllowDayOverflow allowOverflow = AllowDayOverflow.yes,
  Direction dir = Direction.both
)
if (isIntegral!T);

Parameters

NameDescription
years The number of years to expand the interval by.
months The number of months to expand the interval by.
allowOverflow Whether the days should be allowed to overflow on begin and end, causing their month to increment.
dir The direction in time to expand the interval.

Throws

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

Example

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.expand(2);
assert(interval1 == Interval!Date(Date(1994, 1, 2), Date(2014, 3, 1)));

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

Authors

Jonathan M Davis

License

Boost License 1.0.