everyDuration

Range-generating function.

Returns a delegate which returns the next time point which is the given number of years, month, and duration later.

The difference between this version of everyDuration and the version which just takes a core.time.Duration is that this one also takes the number of years and months (along with an AllowDayOverflow to indicate whether adding years and months should allow the days to overflow).

Note that if iterating forward, add!"years"() is called on the given time point, then add!"months"(), and finally the duration is added to it. However, if iterating backwards, the duration is added first, then add!"months"() is called, and finally add!"years"() is called. That way, going backwards generates close to the same time points that iterating forward does, but since adding years and months is not entirely reversible (due to possible day overflow, regardless of whether AllowDayOverflow.yes or AllowDayOverflow.no is used), it can't be guaranteed that iterating backwards will give the same time points as iterating forward would have (even assuming that the end of the range is a time point which would be returned by the delegate when iterating forward from begin).

  1. TP delegate(return scope const TP) everyDuration(D duration)
  2. TP delegate(scope const TP) everyDuration(int years, int months, AllowDayOverflow allowOverflow, D duration)
    nothrow
    TP delegate
    (
    scope const TP
    )
    everyDuration
    ()
    if (
    __traits(compiles, TP.init + duration)
    &&
    __traits(compiles, TP.init.add!"years"(years))
    &&
    __traits(compiles, TP.init.add!"months"(months))
    &&
    (
    dir == Direction.fwd ||
    )
    )

Parameters

dir

The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd.

years int

The number of years to add to the time point passed to the delegate.

months int

The number of months to add to the time point passed to the delegate.

allowOverflow AllowDayOverflow

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

duration D

The duration to add to the time point passed to the delegate.

Examples

import core.time : dur;
import std.datetime.date : AllowDayOverflow, Date;

auto interval = Interval!Date(Date(2010, 9, 2), Date(2025, 9, 27));
auto func = everyDuration!Date(4, 1, AllowDayOverflow.yes, dur!"days"(2));
auto range = interval.fwdRange(func);

// Using PopFirst.yes would have made this Date(2014, 10, 12).
assert(range.front == Date(2010, 9, 2));

range.popFront();
assert(range.front == Date(2014, 10, 4));

range.popFront();
assert(range.front == Date(2018, 11, 6));

range.popFront();
assert(range.front == Date(2022, 12, 8));

range.popFront();
assert(range.empty);

Meta