CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | Static Public Member Functions | Friends | List of all members
CppCommon::Timespan Class Reference

Timespan. More...

#include <timespan.h>

Public Member Functions

 Timespan () noexcept
 Initialize timespan with a zero time duration. More...
 
 Timespan (int64_t duration) noexcept
 Initialize timespan with a given time duration value in nanoseconds. More...
 
template<class Rep , class Period >
 Timespan (const std::chrono::duration< Rep, Period > &duration) noexcept
 Initialize timespan with a given std::chrono duration. More...
 
 Timespan (const Timespan &) noexcept=default
 
 Timespan (Timespan &&) noexcept=default
 
 ~Timespan () noexcept=default
 
Timespanoperator= (int64_t duration) noexcept
 
Timespanoperator= (const Timespan &) noexcept=default
 
Timespanoperator= (Timespan &&) noexcept=default
 
Timespan operator+ () const
 
Timespan operator- () const
 
Timespanoperator+= (int64_t offset) noexcept
 
Timespanoperator+= (const Timespan &offset) noexcept
 
Timespanoperator-= (int64_t offset) noexcept
 
Timespanoperator-= (const Timespan &offset) noexcept
 
std::chrono::system_clock::duration chrono () const noexcept
 Convert timespan to the std::chrono nanoseconds duration. More...
 
int64_t days () const noexcept
 Get total days of the current timespan. More...
 
int64_t hours () const noexcept
 Get total hours of the current timespan. More...
 
int64_t minutes () const noexcept
 Get total minutes of the current timespan. More...
 
int64_t seconds () const noexcept
 Get total seconds of the current timespan. More...
 
int64_t milliseconds () const noexcept
 Get total milliseconds of the current timespan. More...
 
int64_t microseconds () const noexcept
 Get total microseconds of the current timespan. More...
 
int64_t nanoseconds () const noexcept
 Get total nanoseconds of the current timespan. More...
 
int64_t total () const noexcept
 Get total value of the current timespan (total nanoseconds) More...
 
void swap (Timespan &timespan) noexcept
 Swap two instances. More...
 

Static Public Member Functions

static Timespan days (int64_t days) noexcept
 Create the timespan based on the given days value. More...
 
static Timespan hours (int64_t hours) noexcept
 Create the timespan based on the given hours value. More...
 
static Timespan minutes (int64_t minutes) noexcept
 Create the timespan based on the given minutes value. More...
 
static Timespan seconds (int64_t seconds) noexcept
 Create the timespan based on the given seconds value. More...
 
static Timespan milliseconds (int64_t milliseconds) noexcept
 Create the timespan based on the given milliseconds value. More...
 
static Timespan microseconds (int64_t microseconds) noexcept
 Create the timespan based on the given microseconds value. More...
 
static Timespan nanoseconds (int64_t nanoseconds) noexcept
 Create the timespan based on the given nanoseconds value. More...
 
static Timespan zero () noexcept
 Get zero timespan. More...
 

Friends

Timespan operator+ (const Timespan &timespan, int64_t offset) noexcept
 
Timespan operator+ (int64_t offset, const Timespan &timespan) noexcept
 
Timespan operator+ (const Timespan &timespan1, const Timespan &timespan2) noexcept
 
Timespan operator- (const Timespan &timespan, int64_t offset) noexcept
 
Timespan operator- (int64_t offset, const Timespan &timespan) noexcept
 
Timespan operator- (const Timespan &timespan1, const Timespan &timespan2) noexcept
 
bool operator== (const Timespan &timespan, int64_t offset) noexcept
 
bool operator== (int64_t offset, const Timespan &timespan) noexcept
 
bool operator== (const Timespan &timespan1, const Timespan &timespan2) noexcept
 
bool operator!= (const Timespan &timespan, int64_t offset) noexcept
 
bool operator!= (int64_t offset, const Timespan &timespan) noexcept
 
bool operator!= (const Timespan &timespan1, const Timespan &timespan2) noexcept
 
bool operator> (const Timespan &timespan, int64_t offset) noexcept
 
bool operator> (int64_t offset, const Timespan &timespan) noexcept
 
bool operator> (const Timespan &timespan1, const Timespan &timespan2) noexcept
 
bool operator< (const Timespan &timespan, int64_t offset) noexcept
 
bool operator< (int64_t offset, const Timespan &timespan) noexcept
 
bool operator< (const Timespan &timespan1, const Timespan &timespan2) noexcept
 
bool operator>= (const Timespan &timespan, int64_t offset) noexcept
 
bool operator>= (int64_t offset, const Timespan &timespan) noexcept
 
bool operator>= (const Timespan &timespan1, const Timespan &timespan2) noexcept
 
bool operator<= (const Timespan &timespan, int64_t offset) noexcept
 
bool operator<= (int64_t offset, const Timespan &timespan) noexcept
 
bool operator<= (const Timespan &timespan1, const Timespan &timespan2) noexcept
 
void swap (Timespan &timespan1, Timespan &timespan2) noexcept
 

Detailed Description

Timespan.

Timespan wraps time duration in nanoseconds or difference between two timestamps and allows to get separate values of days, hours, minutes, seconds, milliseconds, microseconds or nanoseconds.

Not thread-safe.

Examples
time_timespan.cpp.

Definition at line 26 of file timespan.h.

Constructor & Destructor Documentation

◆ Timespan() [1/5]

CppCommon::Timespan::Timespan ( )
inlinenoexcept

Initialize timespan with a zero time duration.

Definition at line 30 of file timespan.h.

◆ Timespan() [2/5]

CppCommon::Timespan::Timespan ( int64_t  duration)
inlineexplicitnoexcept

Initialize timespan with a given time duration value in nanoseconds.

Parameters
duration- Time duration value in nanoseconds

Definition at line 35 of file timespan.h.

◆ Timespan() [3/5]

template<class Rep , class Period >
CppCommon::Timespan::Timespan ( const std::chrono::duration< Rep, Period > &  duration)
inlineexplicitnoexcept

Initialize timespan with a given std::chrono duration.

Parameters
duration- std::chrono duration

Definition at line 41 of file timespan.h.

◆ Timespan() [4/5]

CppCommon::Timespan::Timespan ( const Timespan )
defaultnoexcept

◆ Timespan() [5/5]

CppCommon::Timespan::Timespan ( Timespan &&  )
defaultnoexcept

◆ ~Timespan()

CppCommon::Timespan::~Timespan ( )
defaultnoexcept

Member Function Documentation

◆ chrono()

std::chrono::system_clock::duration CppCommon::Timespan::chrono ( ) const
inlinenoexcept

Convert timespan to the std::chrono nanoseconds duration.

Definition at line 125 of file timespan.h.

◆ days() [1/2]

int64_t CppCommon::Timespan::days ( ) const
inlinenoexcept

Get total days of the current timespan.

Examples
time_timespan.cpp.

Definition at line 129 of file timespan.h.

◆ days() [2/2]

static Timespan CppCommon::Timespan::days ( int64_t  days)
inlinestaticnoexcept

Create the timespan based on the given days value.

Definition at line 155 of file timespan.h.

◆ hours() [1/2]

int64_t CppCommon::Timespan::hours ( ) const
inlinenoexcept

Get total hours of the current timespan.

Examples
time_timespan.cpp.

Definition at line 132 of file timespan.h.

◆ hours() [2/2]

static Timespan CppCommon::Timespan::hours ( int64_t  hours)
inlinestaticnoexcept

Create the timespan based on the given hours value.

Definition at line 158 of file timespan.h.

◆ microseconds() [1/2]

int64_t CppCommon::Timespan::microseconds ( ) const
inlinenoexcept

Get total microseconds of the current timespan.

Definition at line 144 of file timespan.h.

◆ microseconds() [2/2]

static Timespan CppCommon::Timespan::microseconds ( int64_t  microseconds)
inlinestaticnoexcept

Create the timespan based on the given microseconds value.

Definition at line 170 of file timespan.h.

◆ milliseconds() [1/2]

int64_t CppCommon::Timespan::milliseconds ( ) const
inlinenoexcept

◆ milliseconds() [2/2]

static Timespan CppCommon::Timespan::milliseconds ( int64_t  milliseconds)
inlinestaticnoexcept

Create the timespan based on the given milliseconds value.

Definition at line 167 of file timespan.h.

◆ minutes() [1/2]

int64_t CppCommon::Timespan::minutes ( ) const
inlinenoexcept

Get total minutes of the current timespan.

Examples
time_timespan.cpp.

Definition at line 135 of file timespan.h.

◆ minutes() [2/2]

static Timespan CppCommon::Timespan::minutes ( int64_t  minutes)
inlinestaticnoexcept

Create the timespan based on the given minutes value.

Definition at line 161 of file timespan.h.

◆ nanoseconds() [1/2]

int64_t CppCommon::Timespan::nanoseconds ( ) const
inlinenoexcept

Get total nanoseconds of the current timespan.

Definition at line 147 of file timespan.h.

◆ nanoseconds() [2/2]

static Timespan CppCommon::Timespan::nanoseconds ( int64_t  nanoseconds)
inlinestaticnoexcept

Create the timespan based on the given nanoseconds value.

Definition at line 173 of file timespan.h.

◆ operator+()

Timespan CppCommon::Timespan::operator+ ( ) const
inline

Definition at line 52 of file timespan.h.

◆ operator+=() [1/2]

Timespan& CppCommon::Timespan::operator+= ( const Timespan offset)
inlinenoexcept

Definition at line 59 of file timespan.h.

◆ operator+=() [2/2]

Timespan& CppCommon::Timespan::operator+= ( int64_t  offset)
inlinenoexcept

Definition at line 57 of file timespan.h.

◆ operator-()

Timespan CppCommon::Timespan::operator- ( ) const
inline

Definition at line 54 of file timespan.h.

◆ operator-=() [1/2]

Timespan& CppCommon::Timespan::operator-= ( const Timespan offset)
inlinenoexcept

Definition at line 64 of file timespan.h.

◆ operator-=() [2/2]

Timespan& CppCommon::Timespan::operator-= ( int64_t  offset)
inlinenoexcept

Definition at line 62 of file timespan.h.

◆ operator=() [1/3]

Timespan& CppCommon::Timespan::operator= ( const Timespan )
defaultnoexcept

◆ operator=() [2/3]

Timespan& CppCommon::Timespan::operator= ( int64_t  duration)
inlinenoexcept

Definition at line 46 of file timespan.h.

◆ operator=() [3/3]

Timespan& CppCommon::Timespan::operator= ( Timespan &&  )
defaultnoexcept

◆ seconds() [1/2]

int64_t CppCommon::Timespan::seconds ( ) const
inlinenoexcept

Get total seconds of the current timespan.

Examples
time_timespan.cpp, and time_timezone.cpp.

Definition at line 138 of file timespan.h.

◆ seconds() [2/2]

static Timespan CppCommon::Timespan::seconds ( int64_t  seconds)
inlinestaticnoexcept

Create the timespan based on the given seconds value.

Definition at line 164 of file timespan.h.

◆ swap()

void CppCommon::Timespan::swap ( Timespan timespan)
inlinenoexcept

Swap two instances.

Definition at line 11 of file timespan.inl.

◆ total()

int64_t CppCommon::Timespan::total ( ) const
inlinenoexcept

Get total value of the current timespan (total nanoseconds)

Definition at line 151 of file timespan.h.

◆ zero()

static Timespan CppCommon::Timespan::zero ( )
inlinestaticnoexcept

Get zero timespan.

Thread-safe.

Returns
Zero timestamp

Definition at line 182 of file timespan.h.

Friends And Related Function Documentation

◆ operator!= [1/3]

bool operator!= ( const Timespan timespan,
int64_t  offset 
)
friend

Definition at line 89 of file timespan.h.

◆ operator!= [2/3]

bool operator!= ( const Timespan timespan1,
const Timespan timespan2 
)
friend

Definition at line 93 of file timespan.h.

◆ operator!= [3/3]

bool operator!= ( int64_t  offset,
const Timespan timespan 
)
friend

Definition at line 91 of file timespan.h.

◆ operator+ [1/3]

Timespan operator+ ( const Timespan timespan,
int64_t  offset 
)
friend

Definition at line 67 of file timespan.h.

◆ operator+ [2/3]

Timespan operator+ ( const Timespan timespan1,
const Timespan timespan2 
)
friend

Definition at line 71 of file timespan.h.

◆ operator+ [3/3]

Timespan operator+ ( int64_t  offset,
const Timespan timespan 
)
friend

Definition at line 69 of file timespan.h.

◆ operator- [1/3]

Timespan operator- ( const Timespan timespan,
int64_t  offset 
)
friend

Definition at line 74 of file timespan.h.

◆ operator- [2/3]

Timespan operator- ( const Timespan timespan1,
const Timespan timespan2 
)
friend

Definition at line 78 of file timespan.h.

◆ operator- [3/3]

Timespan operator- ( int64_t  offset,
const Timespan timespan 
)
friend

Definition at line 76 of file timespan.h.

◆ operator< [1/3]

bool operator< ( const Timespan timespan,
int64_t  offset 
)
friend

Definition at line 103 of file timespan.h.

◆ operator< [2/3]

bool operator< ( const Timespan timespan1,
const Timespan timespan2 
)
friend

Definition at line 107 of file timespan.h.

◆ operator< [3/3]

bool operator< ( int64_t  offset,
const Timespan timespan 
)
friend

Definition at line 105 of file timespan.h.

◆ operator<= [1/3]

bool operator<= ( const Timespan timespan,
int64_t  offset 
)
friend

Definition at line 117 of file timespan.h.

◆ operator<= [2/3]

bool operator<= ( const Timespan timespan1,
const Timespan timespan2 
)
friend

Definition at line 121 of file timespan.h.

◆ operator<= [3/3]

bool operator<= ( int64_t  offset,
const Timespan timespan 
)
friend

Definition at line 119 of file timespan.h.

◆ operator== [1/3]

bool operator== ( const Timespan timespan,
int64_t  offset 
)
friend

Definition at line 82 of file timespan.h.

◆ operator== [2/3]

bool operator== ( const Timespan timespan1,
const Timespan timespan2 
)
friend

Definition at line 86 of file timespan.h.

◆ operator== [3/3]

bool operator== ( int64_t  offset,
const Timespan timespan 
)
friend

Definition at line 84 of file timespan.h.

◆ operator> [1/3]

bool operator> ( const Timespan timespan,
int64_t  offset 
)
friend

Definition at line 96 of file timespan.h.

◆ operator> [2/3]

bool operator> ( const Timespan timespan1,
const Timespan timespan2 
)
friend

Definition at line 100 of file timespan.h.

◆ operator> [3/3]

bool operator> ( int64_t  offset,
const Timespan timespan 
)
friend

Definition at line 98 of file timespan.h.

◆ operator>= [1/3]

bool operator>= ( const Timespan timespan,
int64_t  offset 
)
friend

Definition at line 110 of file timespan.h.

◆ operator>= [2/3]

bool operator>= ( const Timespan timespan1,
const Timespan timespan2 
)
friend

Definition at line 114 of file timespan.h.

◆ operator>= [3/3]

bool operator>= ( int64_t  offset,
const Timespan timespan 
)
friend

Definition at line 112 of file timespan.h.

◆ swap

void swap ( Timespan timespan1,
Timespan timespan2 
)
friend

Definition at line 17 of file timespan.inl.


The documentation for this class was generated from the following files: