|
| duration (double v=0) |
| Constructs a duration with the value set to v . More...
|
|
template<uint64_t convertfrom> |
| duration (const asap::duration< convertfrom > &other) |
| Converts the value of other to construct an asap::duration More...
|
|
| operator double () const |
| Converts an asap::duration to double in the same 2456convertion factor specified (e.g, 0.5 days, if using asap::days)
|
|
duration< convert > & | operator= (double v) |
| Sets the internal value to v . More...
|
|
double | operator* () const |
| the same as asap::duration::operator double() More...
|
|
duration< convert > | operator- () |
| Changes the sign of a duration. More...
|
|
template<uint64_t other> |
| operator duration< other > () const |
| Converts an duration to another duration factor (e.g, convert an asap::day to an asap::year ) More...
|
|
template<uint64_t convert2> |
duration< convert > & | operator+= (const duration< convert2 > &other) |
| Adds another duration to this duration, converting to this convertion factor (e.g, 1_day + 1_week == 1_day + 7_days ) More...
|
|
duration< convert > & | operator+= (const duration< convert > &other) |
| Adds another duration to this duration with the same convertion factor. More...
|
|
template<uint64_t convert2> |
duration< convert > & | operator-= (const duration< convert2 > &other) |
| Subtracts another duration from this duration, converting to this convertion factor (e.g, 1_day -= 1_week == 1_day -= 7_days ) More...
|
|
template<uint64_t convert2> |
duration< convert > & | operator= (const duration< convert2 > &other) |
| Sets this duration as equals to another duration, converting to this convertion factor (e.g, asap::days d = 1_week == asap::days d = 7_days ) More...
|
|
std::string | str () const |
| Pretty print this duration, breaking down all the units (e.g: std::cout << 10_days would print 1 week, 3 days ) More...
|
|
template<uint64_t convert = 1>
class asap::duration< convert >
The asap::duration class exposes methods to create, manipulate and print durations.
- Template Parameters
-
convert | The multiplier in seconds for this duration |
A duration is an unbounded period of time. It does not have a start datetime nor an end. They can be obtained via the following helper classes:
All of them have singular equivalents (e.g, asap::minute
) for convenience. They can also be constructed from literals available in the asap::literals
namespace. Consult the asap::literals
documentation for more about ASAP literals.
Note that they all work with floating point values, so you can specify fractions of a duration:
You can add and subtract durations from each other. The right-hand operand will be converted to the same "*base*" as the left-hand operator (e.g, if you add asap::seconds
to asap::year
, the year will be converted to seconds and then added). For this reason is not advisable to add periods with large different convertion factors between the left and the right operands. It is ok to add a year to a second, but seconds added to a year can have rounding issues as it will be converted to a fraction of a year.
Subtracting an asap::datetime
from another will give you an asap::duration
:
You can also add or subtract durations from asap::datetime
objects:
Literals
The file literals.h has many user-defined literals to provide eye-candy to your code when construction durations:
You have to explicitly include these literals by adding the following in your code that is using ASAP:
These literals can be used as a shorthand for their class counterpart:
std::cout <<
asap::now() + 2_days - 1_hour << std::endl;
Definition at line 28 of file duration.h.