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.

Struct std.datetime.interval.IntervalRange

A range over an Interval.

struct IntervalRange(TP, Direction dir)
  
if (isTimePoint!TP && (dir != Direction.both));

IntervalRange is only ever constructed by Interval. However, when it is constructed, it is given a function, func, which is used to generate the time points which are iterated over. func takes a time point and returns a time point of the same type. For instance, to iterate over all of the days in the interval Interval!Date, pass a function to Interval's fwdRange where that function took a Date and returned a Date which was one day later. That function would then be used by IntervalRange's popFront to iterate over the Dates in the interval.

If dir == Direction.fwd, then a range iterates forward in time, whereas if dir == Direction.bwd, then it iterates backwards in time. So, if dir == Direction.fwd then front == interval.begin, whereas if dir == Direction.bwd then front == interval.end. func must generate a time point going in the proper direction of iteration, or a DateTimeException will be thrown. So, to iterate forward in time, the time point that func generates must be later in time than the one passed to it. If it's either identical or earlier in time, then a DateTimeException will be thrown. To iterate backwards, then the generated time point must be before the time point which was passed in.

If the generated time point is ever passed the edge of the range in the proper direction, then the edge of that range will be used instead. So, if iterating forward, and the generated time point is past the interval's end, then front becomes end. If iterating backwards, and the generated time point is before begin, then front becomes begin. In either case, the range would then be empty.

Also note that while normally the begin of an interval is included in it and its end is excluded from it, if dir == Direction.bwd, then begin is treated as excluded and end is treated as included. This allows for the same behavior in both directions. This works because none of Interval's functions which care about whether begin or end is included or excluded are ever called by IntervalRange. interval returns a normal interval, regardless of whether dir == Direction.fwd or if dir == Direction.bwd, so any Interval functions which are called on it which care about whether begin or end are included or excluded will treat begin as included and end as excluded.

Properties

NameTypeDescription
direction[get] DirectionThe Direction that this range iterates in.
empty[get] boolWhether this IntervalRange is empty.
front[get] TPThe first time point in the range.
func[get] TP delegate(scope const TP)The function used to generate the next time point in the range.
interval[get] Interval!TPThe interval that this IntervalRange currently covers.
save[get] IntervalRangeReturns a copy of this.

Methods

NameDescription
opAssign
popFront Pops front from the range, using func to generate the next time point in the range. If the generated time point is beyond the edge of the range, then front is set to that edge, and the range is then empty. So, if iterating forwards, and the generated time point is greater than the interval's end, then front is set to end. If iterating backwards, and the generated time point is less than the interval's begin, then front is set to begin.

Authors

Jonathan M Davis

License

Boost License 1.0.