std.datetime.every_duration
- multiple declarations
- Function everyDuration
- Function everyDuration
Function everyDuration
Range-generating function.
Returns a delegate which returns the next time point which is the given
duration
later.
Using this delegate allows iteration over successive time points which
are apart by the given duration
e.g. passing dur!"days"(3)
to
would result in a delegate which could be used to iterate
over a range of days which are each 3 days apart.
everyDuration
Prototype
TP delegate(in TP) everyDuration(TP, std.datetime.Direction dir, D)( D duration ) nothrow if (isTimePoint!TP && __traits(compiles, TP.init + duration) && (dir == Direction.fwd || dir == Direction.bwd));
Parameters
Name | Description |
---|---|
dir | The direction to iterate in. If passing the return value to
fwdRange , use . If passing it to
bwdRange , use . |
duration | The duration which separates each successive time point in
the range. |
Example
auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27)); auto func = everyDuration!Date(dur!"days"(8)); auto range = interval.fwdRange(func); //Using PopFirst.yes would have made this Date(2010, 9, 10). assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(range.front == Date(2010, 9, 10)); range.popFront(); assert(range.front == Date(2010, 9, 18)); range.popFront(); assert(range.front == Date(2010, 9, 26)); range.popFront(); assert(range.empty);
Function everyDuration
Range-generating function.
Returns a delegate which returns the next time point which is the given
number of years
, month, and duration
later.
The difference between this version of
and the version
which just takes a everyDuration
core.time.Duration
is that this one also takes the number of
years
and months
(along with an
to indicate whether
adding AllowDayOverflow
years
and months
should allow the days to overflow).
Note that if iterating forward, add!"
is called on the given
time point, then years
"()add!"
, and finally the months
"()duration
is added
to it. However, if iterating backwards, the duration
is added first, then
add!"
is called, and finally months
"()add!"
is called.
That way, going backwards generates close to the same time points that
iterating forward does, but since adding years
"()years
and months
is not entirely
reversible (due to possible day overflow, regardless of whether
or AllowDayOverflow.yes
is used), it can't be
guaranteed that iterating backwards will give the same time points as
iterating forward would have (even assuming that the end of the range is a
time point which would be returned by the delegate when iterating forward
from AllowDayOverflow.no
begin
).
Prototype
TP delegate(in TP) everyDuration(TP, std.datetime.Direction dir, D)( int years, int months = 0, AllowDayOverflow allowOverflow = AllowDayOverflow.yes, D duration = dur!"days"(0) ) nothrow if (isTimePoint!TP && __traits(compiles, TP.init + duration) && __traits(compiles, TP.init.add!"years"(years)) && __traits(compiles, TP.init.add!"months"(months)) && (dir == Direction.fwd || dir == Direction.bwd));
Parameters
Name | Description |
---|---|
dir | The direction to iterate in. If passing the return
value to fwdRange , use . If
passing it to bwdRange , use . |
years | The number of years to add to the time point passed to
the delegate. |
months | The number of months to add to the time point passed to
the delegate. |
allowOverflow | Whether the days should be allowed to overflow on
begin and end , causing their month to
increment. |
duration | The duration to add to the time point passed to the
delegate. |
Example
auto interval = Interval!Date(Date(2010, 9, 2), Date(2025, 9, 27)); auto func = everyDuration!Date(4, 1, AllowDayOverflow.yes, dur!"days"(2)); auto range = interval.fwdRange(func); //Using PopFirst.yes would have made this Date(2014, 10, 12). assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(range.front == Date(2014, 10, 4)); range.popFront(); assert(range.front == Date(2018, 11, 6)); range.popFront(); assert(range.front == Date(2022, 12, 8)); range.popFront(); assert(range.empty);
Authors
Jonathan M Davis and Kato Shoichi