View source code Display the source code in std/datetime.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.datetime.everyMonth

Range-generating function.

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.

Prototype

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

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.

Example

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).
assert(range.front == Date(2000, 1, 30));

range.popFront();
assert(range.front == Date(2000, 2, 29));

range.popFront();
assert(range.front == Date(2001, 2, 28));

range.popFront();
assert(range.front == Date(2002, 2, 28));

range.popFront();
assert(range.front == Date(2003, 2, 28));

range.popFront();
assert(range.front == Date(2004, 2, 28));

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

Authors

Jonathan M Davis and Kato Shoichi

License

Boost License 1.0.

Comments