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.everyDayOfWeek

Range-generating function.

Returns a delegate which returns the next time point with the given DayOfWeek in a range.

Using this delegate allows iteration over successive time points which are all the same day of the week. e.g. passing DayOfWeek.mon to everyDayOfWeek would result in a delegate which could be used to iterate over all of the Mondays in a range.

Prototype

TP delegate(in TP) everyDayOfWeek(TP, std.datetime.Direction dir)(
  DayOfWeek dayOfWeek
) nothrow
if (isTimePoint!TP && (dir == Direction.fwd || dir == Direction.bwd) && __traits(hasMember, TP, "dayOfWeek") && !__traits(isStaticFunction, TP.dayOfWeek) && is(typeof(TP.dayOfWeek) == DayOfWeek));

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.
dayOfWeek The week that each time point in the range will be.

Example

auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27));
auto func = everyDayOfWeek!Date(DayOfWeek.mon);
auto range = interval.fwdRange(func);

//A Thursday. Using PopFirst.yes would have made this Date(2010, 9, 6).
assert(range.front == Date(2010, 9, 2));

range.popFront();
assert(range.front == Date(2010, 9, 6));

range.popFront();
assert(range.front == Date(2010, 9, 13));

range.popFront();
assert(range.front == Date(2010, 9, 20));

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

Authors

Jonathan M Davis and Kato Shoichi

License

Boost License 1.0.

Comments