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.

Function std.datetime.interval.everyMonth

Range-generating function.

TP delegate(scope const TP) everyMonth(TP, Direction dir = Direction.fwd) (
  int month
)
if (isTimePoint!TP && (dir == Direction.fwd || dir == Direction.bwd) && __traits(hasMember, TP, "month") && !__traits(isStaticFunction, TP.month) && is(typeof(TP.month) == Month));

Returns a delegate which returns the next time point with the given month which would be reached by adding months to the given time point.

So, using this delegate allows iteration over successive time points which are in the same month but different years. For example, iterate over each successive December 25th in an interval by starting with a date which had the 25th as its day and passed Month.dec to everyMonth to create the delegate.

Since it wouldn't really make sense to be iterating over a specific month and end up with some of the time points in the succeeding month or two years after the previous time point, AllowDayOverflow.no is always used when calculating the next time point.

Parameters

NameDescription
dir The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd.
month The month that each time point in the range will be in (January is 1).

Example

import std.datetime.date : Date, Month;

auto interval = Interval!Date(Date(2000, 1, 30), Date(2004, 8, 5));
auto func = everyMonth!Date(Month.feb);
auto range = interval.fwdRange(func);

// Using PopFirst.yes would have made this Date(2010, 2, 29).
writeln(range.front); // Date(2000, 1, 30)

range.popFront();
writeln(range.front); // Date(2000, 2, 29)

range.popFront();
writeln(range.front); // Date(2001, 2, 28)

range.popFront();
writeln(range.front); // Date(2002, 2, 28)

range.popFront();
writeln(range.front); // Date(2003, 2, 28)

range.popFront();
writeln(range.front); // Date(2004, 2, 28)

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

Authors

Jonathan M Davis

License

Boost License 1.0.