ASAP  1.0.0
A C++ header-only library for creating, displaying, iterating and manipulating dates
Classes | Typedefs | Functions | Variables
asap Namespace Reference

Classes

class  datetime
 The asap::datetime class exposes methods to create, manipulate and print dates. More...
 
class  duration
 The asap::duration class exposes methods to create, manipulate and print durations. More...
 
class  period
 The asap::period class is a bound period, with starting and ending dates. Its purpose is to provide datetime iteration. More...
 

Typedefs

using seconds = duration< 1 >
 A duration specified in seconds.
 
using second = seconds
 A duration specified in seconds.
 
using minutes = duration< SECONDS_IN_MINUTE >
 A duration specified in minutes.
 
using minute = minutes
 A duration specified in minutes.
 
using hours = duration< SECONDS_IN_HOUR >
 A duration specified in hours.
 
using hour = hours
 A duration specified in hours.
 
using days = duration< SECONDS_IN_DAY >
 A duration specified in days.
 
using day = days
 A duration specified in days.
 
using weeks = duration< SECONDS_IN_WEEK >
 A duration specified in weeks (7 days)
 
using week = weeks
 A duration specified in weeks (7 days)
 
using months = duration< SECONDS_IN_MONTH >
 A duration specified in months (30 days)
 
using month = months
 A duration specified in months (30 days)
 
using years = duration< SECONDS_IN_YEAR >
 A duration specified in years.
 
using year = years
 A duration specified in years.
 

Functions

static asap::datetime now ()
 Creates an asap::datetime instance representing current time. More...
 
static asap::datetime tomorrow ()
 Creates an asap::datetime instance representing the next day at 00:00:00. More...
 
static asap::datetime yesterday ()
 Creates an asap::datetime instance representing the previous day at 00:00:00. More...
 
template<uint64_t convert>
static asap::datetime operator+ (const asap::datetime &a, const duration< convert > &b)
 Adds a duration to a datetime. More...
 
template<uint64_t convert>
static asap::datetime operator- (const asap::datetime &a, const duration< convert > &b)
 Subtracts a duration from a datetime. More...
 
static asap::datetime operator+ (const asap::datetime &a, std::time_t b)
 Adds a duration specified in a time_t to a datetime. More...
 
static asap::datetime operator- (const asap::datetime &a, std::time_t b)
 Subtracts a duration specified in a time_t from a datetime. More...
 
template<uint64_t c1, uint64_t c2>
static duration< c1 > operator+ (const duration< c1 > &a, const duration< c2 > &b)
 Adds two durations. More...
 
template<uint64_t conv>
static duration< conv > operator+ (const duration< conv > &a, const duration< conv > &b)
 Adds two durations of the same converting factor. More...
 
template<uint64_t c1, uint64_t c2>
static duration< c1 > operator- (const duration< c1 > &a, const duration< c2 > &b)
 Subtracts two durations. More...
 
template<uint64_t c1>
static duration< c1 > operator- (const duration< c1 > &a)
 Inverts the sign of the duration. More...
 
static bool operator< (const asap::datetime &a, const asap::datetime &b)
 Compares if a < b is true for two asap::datetime instances. More...
 
static bool operator> (const asap::datetime &a, const asap::datetime &b)
 Compares if a > b is true for two asap::datetime instances. More...
 
static bool operator== (const asap::datetime &a, const asap::datetime &b)
 Compares if a == b is true for two asap::datetime instances. More...
 
template<typename ostream >
static ostream & operator<< (ostream &os, const asap::datetime &dt)
 Inserts a datetime into an standard output stream. More...
 
template<typename ostream , uint64_t convert>
static ostream & operator<< (ostream &os, const duration< convert > &du)
 Inserts a duration into an standard output stream. More...
 

Variables

static constexpr uint64_t SECONDS_IN_MINUTE = 60
 Specifies how many seconds there is in a standard minute of 60 seconds.
 
static constexpr uint64_t SECONDS_IN_HOUR = SECONDS_IN_MINUTE * 60
 Specifies how many seconds there is in a standard hour of 60 minutes.
 
static constexpr uint64_t SECONDS_IN_DAY = SECONDS_IN_HOUR * 24
 Specifies how many seconds there is in a standard day of 24 hours.
 
static constexpr uint64_t SECONDS_IN_MONTH = SECONDS_IN_DAY * 30
 Specifies how many seconds there is in a standard month of 30 days.
 
static constexpr uint64_t SECONDS_IN_YEAR = SECONDS_IN_DAY * 365
 Specifies how many seconds there is in a standard year of 365 days.
 
static constexpr uint64_t SECONDS_IN_WEEK = SECONDS_IN_DAY * 7
 Specifies how many seconds there is in a standard week of 7 days.
 

Detailed Description

The asap namespace contains all symbols, classes and functions for the ASAP library

Function Documentation

◆ now()

asap::now ( )
inlinestatic

Creates an asap::datetime instance representing current time.

Returns
an asap::datetime instance

Definition at line 39 of file asap.h.

◆ operator+() [1/4]

template<uint64_t convert>
static asap::datetime asap::operator+ ( const asap::datetime a,
const duration< convert > &  b 
)
inlinestatic

Adds a duration to a datetime.

Template Parameters
convertthe converting factor for the duration (automatically deduced)
Parameters
athe datetime
bthe duration
Returns
a new datetime equivalent to a + b

Definition at line 36 of file operators.h.

◆ operator+() [2/4]

static asap::datetime asap::operator+ ( const asap::datetime a,
std::time_t  b 
)
inlinestatic

Adds a duration specified in a time_t to a datetime.

Parameters
athe datetime
bthe duration in seconds since epoch (time_t)
Returns
a new datetime equivalent to a + b

Definition at line 63 of file operators.h.

◆ operator+() [3/4]

template<uint64_t c1, uint64_t c2>
static duration<c1> asap::operator+ ( const duration< c1 > &  a,
const duration< c2 > &  b 
)
inlinestatic

Adds two durations.

Template Parameters
c1the converting factor for the first duration (automatically deduced)
c2the converting factor for the second duration (automatically deduced)
Parameters
aThe first duration
bThe second duration
Returns
A new asap::duration equivalent to a + b converted to the factor of the first operand

Definition at line 90 of file operators.h.

◆ operator+() [4/4]

template<uint64_t conv>
static duration<conv> asap::operator+ ( const duration< conv > &  a,
const duration< conv > &  b 
)
inlinestatic

Adds two durations of the same converting factor.

Template Parameters
convthe converting factor for the second duration (automatically deduced)
Parameters
aThe first duration
bThe second duration
Returns
A new asap::duration equivalent to a + b

Definition at line 104 of file operators.h.

◆ operator-() [1/4]

template<uint64_t convert>
static asap::datetime asap::operator- ( const asap::datetime a,
const duration< convert > &  b 
)
inlinestatic

Subtracts a duration from a datetime.

Template Parameters
convertthe converting factor for the duration (automatically deduced)
Parameters
athe datetime
bthe duration
Returns
a new datetime equivalent to a - b

Definition at line 50 of file operators.h.

◆ operator-() [2/4]

static asap::datetime asap::operator- ( const asap::datetime a,
std::time_t  b 
)
inlinestatic

Subtracts a duration specified in a time_t from a datetime.

Parameters
athe datetime
bthe duration in seconds since epoch (time_t)
Returns
a new datetime equivalent to a - b

Definition at line 75 of file operators.h.

◆ operator-() [3/4]

template<uint64_t c1, uint64_t c2>
static duration<c1> asap::operator- ( const duration< c1 > &  a,
const duration< c2 > &  b 
)
inlinestatic

Subtracts two durations.

Template Parameters
c1the converting factor for the first duration (automatically deduced)
c2the converting factor for the second duration (automatically deduced)
Parameters
aThe first duration
bThe second duration
Returns
A new asap::duration equivalent to a - b converted to the factor of the first operand

Definition at line 119 of file operators.h.

◆ operator-() [4/4]

template<uint64_t c1>
static duration<c1> asap::operator- ( const duration< c1 > &  a)
inlinestatic

Inverts the sign of the duration.

Template Parameters
c1the convert factor of the duration (automatically deduced)
Parameters
aThe duration
Returns
a duration equivalent to -a (e.g, 1 day -> minus 1 day)

Definition at line 132 of file operators.h.

◆ operator<()

static bool asap::operator< ( const asap::datetime a,
const asap::datetime b 
)
inlinestatic

Compares if a < b is true for two asap::datetime instances.

Parameters
aThe first operand
bThe second operand
Returns
true if a < b, false otherwise

Definition at line 144 of file operators.h.

◆ operator<<() [1/2]

template<typename ostream >
static ostream& asap::operator<< ( ostream &  os,
const asap::datetime dt 
)
inlinestatic

Inserts a datetime into an standard output stream.

Template Parameters
ostreamThe output stream type
Parameters
osThe output stream instance
dtThe datetime to insert
Returns
the ostream instance passed in

this allows you to write std::cout << asap::now() << std::endl

Definition at line 177 of file operators.h.

◆ operator<<() [2/2]

template<typename ostream , uint64_t convert>
static ostream& asap::operator<< ( ostream &  os,
const duration< convert > &  du 
)
inlinestatic

Inserts a duration into an standard output stream.

Template Parameters
ostreamThe output stream type
convertThe converting factor for the duration (automatically deduced)
Parameters
osThe output stream instance
duThe duration to insert
Returns
the ostream instance passed in

this allows you to write std::cout << asap::now() << std::endl

Definition at line 191 of file operators.h.

◆ operator==()

static bool asap::operator== ( const asap::datetime a,
const asap::datetime b 
)
inlinestatic

Compares if a == b is true for two asap::datetime instances.

Parameters
aThe first operand
bThe second operand
Returns
true if a == b, false otherwise

Definition at line 164 of file operators.h.

◆ operator>()

static bool asap::operator> ( const asap::datetime a,
const asap::datetime b 
)
inlinestatic

Compares if a > b is true for two asap::datetime instances.

Parameters
aThe first operand
bThe second operand
Returns
true if a > b, false otherwise

Definition at line 154 of file operators.h.

◆ tomorrow()

asap::tomorrow ( )
inlinestatic

Creates an asap::datetime instance representing the next day at 00:00:00.

Returns
an asap::datetime instance

Definition at line 41 of file asap.h.

◆ yesterday()

asap::yesterday ( )
inlinestatic

Creates an asap::datetime instance representing the previous day at 00:00:00.

Returns
an asap::datetime instance

Definition at line 50 of file asap.h.