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

Range-generating function.

TP delegate(in TP) everyDayOfWeek(TP, Direction dir = Direction.fwd) (
  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));

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.

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

import std.datetime.date : Date, DayOfWeek;

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).
writeln(range.front); // Date(2010, 9, 2)

range.popFront();
writeln(range.front); // Date(2010, 9, 6)

range.popFront();
writeln(range.front); // Date(2010, 9, 13)

range.popFront();
writeln(range.front); // Date(2010, 9, 20)

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

Authors

Jonathan M Davis

License

Boost License 1.0.