Struct std.datetime.interval.IntervalRange
A range over an Interval
.
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 Date
s in the interval.
If dir == Direction
, then a range iterates forward in time, whereas
if dir == Direction
, then it iterates backwards in time. So, if
dir == Direction
then front == interval
, whereas if
dir == Direction
then front == interval
. 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
, 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
or if dir == Direction
, 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
Name | Type | Description |
---|---|---|
direction [get]
|
Direction | The Direction that this range iterates in.
|
empty [get]
|
bool | Whether this IntervalRange is empty.
|
front [get]
|
TP | The 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!TP | The interval that this IntervalRange currently covers.
|
save [get]
|
IntervalRange | Returns a copy of this .
|
Methods
Name | Description |
---|---|
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 .
|