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

Time. More...

#include <time.h>

Inheritance diagram for CppCommon::Time:
CppCommon::LocalTime CppCommon::UtcTime

Public Member Functions

 Time () noexcept
 Initialize time with an epoch time. More...
 
 Time (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0, int nanosecond=0)
 Initialize time with a given date & time components (year, month, day, hour, minute, second, etc.) More...
 
 Time (const Time &) noexcept=default
 
 Time (Time &&) noexcept=default
 
 ~Time () noexcept=default
 
Timeoperator= (const Timestamp &timestamp)
 
Timeoperator= (const Time &) noexcept=default
 
Timeoperator= (Time &&) noexcept=default
 
Timeoperator+= (const Timespan &offset)
 
Timeoperator-= (const Timespan &offset)
 
std::chrono::time_point< std::chrono::system_clock > chrono () const
 Convert date & time to the std::chrono time point. More...
 
int year () const noexcept
 Get year value (1970-2038 for 32-bit or 1970-3000 for 64-bit) More...
 
int month () const noexcept
 Get month value (1-12) More...
 
Weekday weekday () const noexcept
 Get weekday. More...
 
int day () const noexcept
 Get day value (1-31) More...
 
int hour () const noexcept
 Get hour value (0-23) More...
 
int minute () const noexcept
 Get minute value (0-59) More...
 
int second () const noexcept
 Get second value (0-59) More...
 
int millisecond () const noexcept
 Get millisecond value (0-999) More...
 
int microsecond () const noexcept
 Get microsecond value (0-999) More...
 
int nanosecond () const noexcept
 Get nanosecond value (0-999) More...
 
UtcTimestamp utcstamp () const
 Get UTC timestamp from the current date & time value. More...
 
LocalTimestamp localstamp () const
 Get local timestamp from the current date & time value. More...
 
void swap (Time &time) noexcept
 Swap two instances. More...
 

Static Public Member Functions

static Time epoch ()
 Get the epoch date & time. More...
 

Protected Member Functions

 Time (const Timestamp &timestamp)
 Protected initialize time with a timestamp. More...
 

Protected Attributes

int _year
 Year value. More...
 
int _month
 Month value. More...
 
int _weekday
 Weekday value. More...
 
int _day
 Day value. More...
 
int _hour
 Hour value. More...
 
int _minute
 Minute value. More...
 
int _second
 Second value. More...
 
int _millisecond
 Millisecond value. More...
 
int _microsecond
 Microsecond value. More...
 
int _nanosecond
 Nanosecond value. More...
 

Friends

Time operator+ (const Time &time, const Timespan &offset)
 
Time operator+ (const Timespan &offset, const Time &time)
 
Time operator- (const Time &time, const Timespan &offset)
 
Time operator- (const Timespan &offset, const Time &time)
 
Timespan operator- (const Time &time1, const Time &time2)
 
bool operator== (const Time &time, const Timestamp &timestamp)
 
bool operator== (const Timestamp &timestamp, const Time &time)
 
bool operator== (const Time &time1, const Time &time2) noexcept
 
bool operator!= (const Time &time, const Timestamp &timestamp)
 
bool operator!= (const Timestamp &timestamp, const Time &time)
 
bool operator!= (const Time &time1, const Time &time2) noexcept
 
bool operator> (const Time &time, const Timestamp &timestamp)
 
bool operator> (const Timestamp &timestamp, const Time &time)
 
bool operator> (const Time &time1, const Time &time2) noexcept
 
bool operator< (const Time &time, const Timestamp &timestamp)
 
bool operator< (const Timestamp &timestamp, const Time &time)
 
bool operator< (const Time &time1, const Time &time2) noexcept
 
bool operator>= (const Time &time, const Timestamp &timestamp)
 
bool operator>= (const Timestamp &timestamp, const Time &time)
 
bool operator>= (const Time &time1, const Time &time2) noexcept
 
bool operator<= (const Time &time, const Timestamp &timestamp)
 
bool operator<= (const Timestamp &timestamp, const Time &time)
 
bool operator<= (const Time &time1, const Time &time2) noexcept
 
void swap (Time &time1, Time &time2) noexcept
 

Detailed Description

Time.

Time wraps date & time in a single object with a set of accessors - year, month, day, hours, minutes, seconds, milliseconds, microseconds or nanoseconds.

32-bit: time is limited in range 1970-01-01T00:00:00Z - 2038-01-18T23:59:59Z 64-bit: time is limited in range 1970-01-01T00:00:00Z - 3000-12-31T23:59:59Z

Not thread-safe.

Examples
time_time.cpp.

Definition at line 47 of file time.h.

Constructor & Destructor Documentation

◆ Time() [1/5]

CppCommon::Time::Time ( )
inlinenoexcept

Initialize time with an epoch time.

Definition at line 44 of file time.inl.

◆ Time() [2/5]

CppCommon::Time::Time ( int  year,
int  month,
int  day,
int  hour = 0,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0,
int  nanosecond = 0 
)
explicit

Initialize time with a given date & time components (year, month, day, hour, minute, second, etc.)

Parameters
year- Year value (1970-2038 for 32-bit or 1970-3000 for 64-bit)
month- Month value (1-12)
day- Day value (1-31)
hour- Hour value (0-23) (default is 0)
minute- Minute value (0-59) (default is 0)
second- Second value (0-59) (default is 0)
millisecond- Millisecond value (0-999) (default is 0)
microsecond- Microsecond value (0-999) (default is 0)
nanosecond- Nanosecond value (0-999) (default is 0)

Definition at line 42 of file time.cpp.

◆ Time() [3/5]

CppCommon::Time::Time ( const Time )
defaultnoexcept

◆ Time() [4/5]

CppCommon::Time::Time ( Time &&  )
defaultnoexcept

◆ ~Time()

CppCommon::Time::~Time ( )
defaultnoexcept

◆ Time() [5/5]

CppCommon::Time::Time ( const Timestamp timestamp)
explicitprotected

Protected initialize time with a timestamp.

Parameters
timestamp- Timestamp

Definition at line 19 of file time.cpp.

Member Function Documentation

◆ chrono()

std::chrono::time_point<std::chrono::system_clock> CppCommon::Time::chrono ( ) const
inline

Convert date & time to the std::chrono time point.

Definition at line 132 of file time.h.

◆ day()

int CppCommon::Time::day ( ) const
inlinenoexcept

Get day value (1-31)

Examples
time_time.cpp.

Definition at line 142 of file time.h.

◆ epoch()

static Time CppCommon::Time::epoch ( )
inlinestatic

Get the epoch date & time.

Thread-safe.

Returns
Epoch date & time

Definition at line 167 of file time.h.

◆ hour()

int CppCommon::Time::hour ( ) const
inlinenoexcept

Get hour value (0-23)

Examples
time_time.cpp.

Definition at line 144 of file time.h.

◆ localstamp()

LocalTimestamp CppCommon::Time::localstamp ( ) const

Get local timestamp from the current date & time value.

Definition at line 122 of file time.cpp.

◆ microsecond()

int CppCommon::Time::microsecond ( ) const
inlinenoexcept

Get microsecond value (0-999)

Examples
time_time.cpp.

Definition at line 152 of file time.h.

◆ millisecond()

int CppCommon::Time::millisecond ( ) const
inlinenoexcept

Get millisecond value (0-999)

Examples
time_time.cpp.

Definition at line 150 of file time.h.

◆ minute()

int CppCommon::Time::minute ( ) const
inlinenoexcept

Get minute value (0-59)

Examples
time_time.cpp.

Definition at line 146 of file time.h.

◆ month()

int CppCommon::Time::month ( ) const
inlinenoexcept

Get month value (1-12)

Examples
time_time.cpp.

Definition at line 138 of file time.h.

◆ nanosecond()

int CppCommon::Time::nanosecond ( ) const
inlinenoexcept

Get nanosecond value (0-999)

Examples
time_time.cpp.

Definition at line 154 of file time.h.

◆ operator+=()

Time& CppCommon::Time::operator+= ( const Timespan offset)
inline

Definition at line 75 of file time.h.

◆ operator-=()

Time& CppCommon::Time::operator-= ( const Timespan offset)
inline

Definition at line 78 of file time.h.

◆ operator=() [1/3]

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

◆ operator=() [2/3]

Time& CppCommon::Time::operator= ( const Timestamp timestamp)
inline

Definition at line 69 of file time.h.

◆ operator=() [3/3]

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

◆ second()

int CppCommon::Time::second ( ) const
inlinenoexcept

Get second value (0-59)

Examples
time_time.cpp.

Definition at line 148 of file time.h.

◆ swap()

void CppCommon::Time::swap ( Time time)
inlinenoexcept

Swap two instances.

Definition at line 259 of file time.inl.

◆ utcstamp()

UtcTimestamp CppCommon::Time::utcstamp ( ) const

Get UTC timestamp from the current date & time value.

Definition at line 100 of file time.cpp.

◆ weekday()

Weekday CppCommon::Time::weekday ( ) const
inlinenoexcept

Get weekday.

Definition at line 140 of file time.h.

◆ year()

int CppCommon::Time::year ( ) const
inlinenoexcept

Get year value (1970-2038 for 32-bit or 1970-3000 for 64-bit)

Examples
time_time.cpp.

Definition at line 136 of file time.h.

Friends And Related Function Documentation

◆ operator!= [1/3]

bool operator!= ( const Time time,
const Timestamp timestamp 
)
friend

Definition at line 101 of file time.h.

◆ operator!= [2/3]

bool operator!= ( const Time time1,
const Time time2 
)
friend

Definition at line 64 of file time.inl.

◆ operator!= [3/3]

bool operator!= ( const Timestamp timestamp,
const Time time 
)
friend

Definition at line 103 of file time.h.

◆ operator+ [1/2]

Time operator+ ( const Time time,
const Timespan offset 
)
friend

Definition at line 81 of file time.h.

◆ operator+ [2/2]

Time operator+ ( const Timespan offset,
const Time time 
)
friend

Definition at line 83 of file time.h.

◆ operator- [1/3]

Time operator- ( const Time time,
const Timespan offset 
)
friend

Definition at line 86 of file time.h.

◆ operator- [2/3]

Timespan operator- ( const Time time1,
const Time time2 
)
friend

Definition at line 91 of file time.h.

◆ operator- [3/3]

Time operator- ( const Timespan offset,
const Time time 
)
friend

Definition at line 88 of file time.h.

◆ operator< [1/3]

bool operator< ( const Time time,
const Timestamp timestamp 
)
friend

Definition at line 113 of file time.h.

◆ operator< [2/3]

bool operator< ( const Time time1,
const Time time2 
)
friend

Definition at line 118 of file time.inl.

◆ operator< [3/3]

bool operator< ( const Timestamp timestamp,
const Time time 
)
friend

Definition at line 115 of file time.h.

◆ operator<= [1/3]

bool operator<= ( const Time time,
const Timestamp timestamp 
)
friend

Definition at line 125 of file time.h.

◆ operator<= [2/3]

bool operator<= ( const Time time1,
const Time time2 
)
friend

Definition at line 212 of file time.inl.

◆ operator<= [3/3]

bool operator<= ( const Timestamp timestamp,
const Time time 
)
friend

Definition at line 127 of file time.h.

◆ operator== [1/3]

bool operator== ( const Time time,
const Timestamp timestamp 
)
friend

Definition at line 95 of file time.h.

◆ operator== [2/3]

bool operator== ( const Time time1,
const Time time2 
)
friend

Definition at line 57 of file time.inl.

◆ operator== [3/3]

bool operator== ( const Timestamp timestamp,
const Time time 
)
friend

Definition at line 97 of file time.h.

◆ operator> [1/3]

bool operator> ( const Time time,
const Timestamp timestamp 
)
friend

Definition at line 107 of file time.h.

◆ operator> [2/3]

bool operator> ( const Time time1,
const Time time2 
)
friend

Definition at line 71 of file time.inl.

◆ operator> [3/3]

bool operator> ( const Timestamp timestamp,
const Time time 
)
friend

Definition at line 109 of file time.h.

◆ operator>= [1/3]

bool operator>= ( const Time time,
const Timestamp timestamp 
)
friend

Definition at line 119 of file time.h.

◆ operator>= [2/3]

bool operator>= ( const Time time1,
const Time time2 
)
friend

Definition at line 165 of file time.inl.

◆ operator>= [3/3]

bool operator>= ( const Timestamp timestamp,
const Time time 
)
friend

Definition at line 121 of file time.h.

◆ swap

void swap ( Time time1,
Time time2 
)
friend

Definition at line 273 of file time.inl.

Member Data Documentation

◆ _day

int CppCommon::Time::_day
protected

Day value.

Definition at line 182 of file time.h.

◆ _hour

int CppCommon::Time::_hour
protected

Hour value.

Definition at line 184 of file time.h.

◆ _microsecond

int CppCommon::Time::_microsecond
protected

Microsecond value.

Definition at line 192 of file time.h.

◆ _millisecond

int CppCommon::Time::_millisecond
protected

Millisecond value.

Definition at line 190 of file time.h.

◆ _minute

int CppCommon::Time::_minute
protected

Minute value.

Definition at line 186 of file time.h.

◆ _month

int CppCommon::Time::_month
protected

Month value.

Definition at line 178 of file time.h.

◆ _nanosecond

int CppCommon::Time::_nanosecond
protected

Nanosecond value.

Definition at line 194 of file time.h.

◆ _second

int CppCommon::Time::_second
protected

Second value.

Definition at line 188 of file time.h.

◆ _weekday

int CppCommon::Time::_weekday
protected

Weekday value.

Definition at line 180 of file time.h.

◆ _year

int CppCommon::Time::_year
protected

Year value.

Definition at line 176 of file time.h.


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