Function std.datetime.interval.everyMonth
Range-generating function.
TP delegate(in 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
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
is always used when
calculating the next time point.
Parameters
Name | Description |
---|---|
dir | The direction to iterate in. If passing the return value to
fwdRange , use Direction . If passing it to
bwdRange , use Direction . |
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);