ASAP
1.0.0
A C++ header-only library for creating, displaying, iterating and manipulating dates
|
The asap::period class is a bound period, with starting and ending dates. Its purpose is to provide datetime iteration. More...
Public Member Functions | |
period (const asap::datetime &a=asap::datetime(), const asap::datetime &b=asap::datetime()) | |
Creates a new peeriod starting at a and ending at b . More... | |
const asap::datetime & | from () const |
Returns an asap::datetime instance marking the beginning of the period. More... | |
void | from (const asap::datetime &begin) |
Sets the beginning of the period. More... | |
const asap::datetime & | to () const |
Returns an asap::datetime instance marking the end of the period. More... | |
void | to (const asap::datetime &end) |
Sets the end of the period. More... | |
template<typename T > | |
T | difference () const |
Calculates the difference between the start and the end. More... | |
asap::seconds | difference () const |
Calculates the difference between the start and the end as seconds. More... | |
template<uint64_t stepconv> | |
asap::detail::accessor< stepconv > | every (const asap::duration< stepconv > &d) const |
Returns an accessor that can be used to iterate between the beginning and the end dates. More... | |
The asap::period class is a bound period, with starting and ending dates. Its purpose is to provide datetime iteration.
You can also use the asap::datetime::until
method to ease construction of asap::period
:
You can specify a period and re-use it as many times as you want:
period::difference()
returns the difference between the end asap::datetime
minus the beginning. You can specify the return type as a template parameter (or you can just crate an asap::duration
from it):
You can also obtain the beginning and the end asap::datetime
from a period using from()
and to()
. You can also use from(datetime)
and to(datetime)
to set the beginning and the end of a period. Existing iterations won't be affected.
|
explicit |
Creates a new peeriod starting at a
and ending at b
.
a | An asap::datetime instance that will be the start of the period |
b | An asap::datetime instance that will mark the end |
asap::period::difference | ( | ) | const |
Calculates the difference between the start and the end.
T | the type to return (e.g, asap::seconds ) |
asap::seconds asap::period::difference | ( | ) | const |
Calculates the difference between the start and the end as seconds.
asap::period::every | ( | const asap::duration< stepconv > & | d | ) | const |
Returns an accessor that can be used to iterate between the beginning and the end dates.
d | The stepping duration (e.g, 1_day) |
This method is useful when iterating between instances of asap::datetime, it returns an accessor that has a begin()
and end()
method, thus allowing you to use range-based for loops or even use iterators.
asap::period::from | ( | ) | const |
Returns an asap::datetime instance marking the beginning of the period.
asap::period::from | ( | const asap::datetime & | begin | ) |
Sets the beginning of the period.
begin | An asap::datetime instance to serve as the beginning |
*this
asap::period::to | ( | ) | const |
Returns an asap::datetime instance marking the end of the period.
asap::period::to | ( | const asap::datetime & | end | ) |
Sets the end of the period.
end | An asap::datetime instance to serve as the end |
*this