ActiveLib
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
active::utility::Time Class Reference

A class to represent a date/time. More...

#include <Time.h>

Public Types

using Option = std::optional<Time>
 Optional.
 

Public Member Functions

 Time (bool isUTCTime=true)
 
 Time (std::filesystem::file_time_type fileTime)
 
 Time (time_t time)
 
 Time (int64_t seconds)
 
 Time (double seconds)
 
 Time (int32_t year, std::chrono::month month, uint8_t day, uint8_t hour=0, uint8_t minute=0, double second=0, int16_t utcOffset=0)
 
Timeoperator= (const std::chrono::system_clock::time_point &source)
 
std::strong_ordering operator<=> (const Time &ref) const
 
bool operator== (const Time &ref) const
 
bool operator!= (const Time &ref) const
 
Timeoperator+= (int32_t days)
 
 operator std::chrono::system_clock::time_point () const
 
std::strong_ordering compare (const Time &ref, std::optional< double > epsMicrosec=std::nullopt) const
 
int64_t year () const
 
std::chrono::month month () const
 
uint8_t day () const
 
uint8_t hour () const
 
uint8_t minute () const
 
uint8_t second () const
 
uint32_t microsecond () const
 
std::pair< int16_t, int16_t > getUTCOffset () const
 
double secondsSince1970 () const
 
double differenceInSeconds (const Time &other) const
 
int64_t differenceInMinutes (const Time &other) const
 
int64_t differenceInHours (const Time &other) const
 
int64_t differenceInDays (const Time &other) const
 
TimesetToCurrent (bool isUTCTime=true)
 
TimeresetTime ()
 
TimeresetDate ()
 
TimeaddDays (int16_t daystoAdd)
 
TimeaddHours (int16_t hourstoAdd)
 
TimeaddMinutes (int16_t minstoAdd)
 
TimeaddSeconds (double secsToAdd)
 
void setHour (uint8_t val)
 
void setMinute (uint8_t val)
 
void setSecond (uint8_t val)
 
void setMicrosecond (uint32_t val)
 
void setUTCOffset (int16_t offset)
 
void setSecondsSince1970 (double totalSeconds)
 

Static Public Attributes

static constexpr uint8_t minDay = 1
 Minimum acceptable day value.
 
static constexpr uint8_t maxDay = 31
 Maximum acceptable day value.
 
static constexpr uint8_t minMonth = 1
 Minimum acceptable month value.
 
static constexpr uint8_t maxMonth = 12
 Maximum acceptable month value.
 
static constexpr uint8_t maxHour = 23
 Maximum acceptable hour value.
 
static constexpr uint8_t maxMinute = 59
 Maximum acceptable minute value.
 
static constexpr uint8_t maxSecond = 59
 Maximum acceptable second value.
 

Detailed Description

A class to represent a date/time.

Constructor & Destructor Documentation

◆ Time() [1/6]

Time::Time ( bool isUTCTime = true)

Constructor

Parameters
isUTCTimeConstruct with UTC time (false = set local time with UTC offset)
Here is the call graph for this function:

◆ Time() [2/6]

Time::Time ( std::filesystem::file_time_type fileTime)

Constructor

Parameters
fileTimeA file system time point

◆ Time() [3/6]

Time::Time ( time_t time)

Constructor

Parameters
timeUnix time

◆ Time() [4/6]

active::utility::Time::Time ( int64_t seconds)
inline

Constructor

Parameters
secondsUnix time

◆ Time() [5/6]

active::utility::Time::Time ( double seconds)
inline

Constructor

Parameters
secondsUnix time

◆ Time() [6/6]

Time::Time ( int32_t year,
std::chrono::month month,
uint8_t day,
uint8_t hour = 0,
uint8_t minute = 0,
double second = 0,
int16_t utcOffset = 0 )

Constructor (NB: Will throw exception if an invalid date is specified)

Parameters
yearThe year
monthThe month
dayThe day
hourThe hour
minuteThe minute
secondThe second
utcOffsetThe UTC offset
Here is the call graph for this function:

Member Function Documentation

◆ addDays()

Time & Time::addDays ( int16_t daystoAdd)

Add a specified number of days to the time

Parameters
daystoAddThe number of days to add (can be negative)
Returns
A reference to this

◆ addHours()

Time & Time::addHours ( int16_t hourstoAdd)

Add a specified number of hours to the time

Parameters
hourstoAddThe number of hours to add (can be negative)
Returns
A reference to this

◆ addMinutes()

Time & Time::addMinutes ( int16_t minstoAdd)

Add a specified number of minutes to the time

Parameters
minstoAddThe number of minutes to add (can be negative)
Returns
A reference to this

◆ addSeconds()

Time & Time::addSeconds ( double secsToAdd)

Add a specified number of seconds to the time

Parameters
secsToAddThe number of seconds to add (can be negative, any fractional part is assigned to milliseconds)
Returns
A reference to this

◆ compare()

std::strong_ordering Time::compare ( const Time & ref,
std::optional< double > epsMicrosec = std::nullopt ) const

Three-way comparison to another time

Parameters
refThe object to compare
epsMicrosecPrecision for comparing the microsecond values (nullopt = use full precision)
Returns
The relationship between this and ref (less, equal, greater)

◆ day()

uint8_t active::utility::Time::day ( ) const
inline

Get the day (1-31)

Returns
The day
Here is the caller graph for this function:

◆ differenceInDays()

int64_t Time::differenceInDays ( const Time & other) const

Get the difference in days between the time in this object and the other input

Parameters
otherThe other time to get the difference to
Returns
The difference in days

◆ differenceInHours()

int64_t Time::differenceInHours ( const Time & other) const

Get the difference in hours between the time in this object and the other input

Parameters
otherThe other time to get the difference to
Returns
The difference in hours

◆ differenceInMinutes()

int64_t Time::differenceInMinutes ( const Time & other) const

Get the difference in minutes between the time in this object and the other input

Parameters
otherThe other time to get the difference to
Returns
The difference in minutes

◆ differenceInSeconds()

double Time::differenceInSeconds ( const Time & other) const

Get the difference in seconds between the time in this object and the other input

Parameters
otherThe other time to get the difference to
Returns
The difference in seconds

◆ getUTCOffset()

std::pair< int16_t, int16_t > Time::getUTCOffset ( ) const

Get the UTC offset

Returns
A pair specifying offset hours and offset minutes
Here is the caller graph for this function:

◆ hour()

uint8_t active::utility::Time::hour ( ) const
inline

Get the hour (0-23)

Returns
The hour
Here is the caller graph for this function:

◆ microsecond()

uint32_t active::utility::Time::microsecond ( ) const
inline

Get the microsecond (0-999999)

Returns
The microsecond
Here is the caller graph for this function:

◆ minute()

uint8_t active::utility::Time::minute ( ) const
inline

Get the minute (0-59)

Returns
The minute
Here is the caller graph for this function:

◆ month()

std::chrono::month active::utility::Time::month ( ) const
inline

Get the month (1 - 12)

Returns
The month
Here is the caller graph for this function:

◆ operator std::chrono::system_clock::time_point()

Time::operator std::chrono::system_clock::time_point ( ) const

Conversion operator

Returns
An equivalent system clock time_point

◆ operator!=()

bool active::utility::Time::operator!= ( const Time & ref) const
inline

Equality operator

Parameters
refThe object to compare
Returns
True if this matches ref

◆ operator+=()

Time & Time::operator+= ( int32_t days)

Addition with assignment operator

Parameters
daysThe number of days to add
Returns
A reference to this

◆ operator<=>()

std::strong_ordering active::utility::Time::operator<=> ( const Time & ref) const
inline

Three-way comparison operator

Parameters
refThe object to compare
Returns
The relationship between this and ref (less, equal, greater)

◆ operator=()

Time & Time::operator= ( const std::chrono::system_clock::time_point & source)

Assignment operator

Parameters
sourceThe object to assign
Returns
A reference to this

◆ operator==()

bool active::utility::Time::operator== ( const Time & ref) const
inline

Equality operator

Parameters
refThe object to compare
Returns
True if this matches ref (NB: microseconds are included in this comparison - use isEqual to control or ignore microseconds)

◆ resetDate()

Time & Time::resetDate ( )

Reset all the calendar date values to zero/start value (leaving the time untouched) return: A reference to this

Here is the caller graph for this function:

◆ resetTime()

Time & Time::resetTime ( )

Reset all the time values to zero (leaving the calendar date untouched) return: A reference to this

Here is the call graph for this function:
Here is the caller graph for this function:

◆ second()

uint8_t active::utility::Time::second ( ) const
inline

Get the second (0-59)

Returns
The second
Here is the caller graph for this function:

◆ secondsSince1970()

double Time::secondsSince1970 ( ) const

Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 (Unix epoch)

Returns
The number of seconds
Here is the caller graph for this function:

◆ setHour()

void active::utility::Time::setHour ( uint8_t val)
inline

Set the hour (0-23)

Here is the caller graph for this function:

◆ setMicrosecond()

void active::utility::Time::setMicrosecond ( uint32_t val)
inline

Set the millisecond (0-999999)

Here is the caller graph for this function:

◆ setMinute()

void active::utility::Time::setMinute ( uint8_t val)
inline

Set the minute (0-59)

Here is the caller graph for this function:

◆ setSecond()

void active::utility::Time::setSecond ( uint8_t val)
inline

Set the second (0-59)

Here is the caller graph for this function:

◆ setSecondsSince1970()

void Time::setSecondsSince1970 ( double totalSeconds)

Set the seconds since 00:00 hours, Jan 1, 1970 UTC

Parameters
totalSecondsThe total seconds since 00:00 hours, Jan 1, 1970 UTC

◆ setToCurrent()

Time & Time::setToCurrent ( bool isUTCTime = true)

Set to the current time

Parameters
isUTCTimeConstruct with UTC time (false = set local time with UTC offset) return: A reference to this
Here is the caller graph for this function:

◆ setUTCOffset()

void active::utility::Time::setUTCOffset ( int16_t offset)
inline

Set the UTC offset (value can be -ve or +ve offset from UTC time)

Parameters
offsetThe UTC offset in minutes (NB: all other date/time values remain unchanged, so the in effect this changes the time-point)
Here is the caller graph for this function:

◆ year()

int64_t active::utility::Time::year ( ) const
inline

Get the year (0 - 32768, e.g. 2011)

Returns
The year
Here is the caller graph for this function:

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