BoosterSeat  0.1
A C++ library that includes common utilities that are used in other projects.
bst::Time Class Reference

The generic time class for BoosterSeat. Uses UTC time. More...

#include <time.hpp>

Collaboration diagram for bst::Time:

Public Member Functions

 Time (bool set_to_now=false)
 Construct a new Time object. Defaults to the epoch. More...
 
 ~Time ()=default
 
bool fromString (const std::string &time_string)
 
unsigned int getDay () const
 Get the Day. More...
 
unsigned int getHour () const
 Get the Hour. More...
 
unsigned int getMinute () const
 Get the Minute. More...
 
unsigned int getMonth () const
 Get the Month (1 - 12) More...
 
unsigned int getSecond () const
 Get the Second. More...
 
time_t getTimeType () const
 
unsigned int getYear () const
 Get the Year. More...
 
bool operator!= (const Time &rhs) const
 
bool operator< (const Time &rhs) const
 
bool operator<= (const Time &rhs) const
 
bool operator== (const Time &rhs) const
 
bool operator> (const Time &rhs) const
 
bool operator>= (const Time &rhs) const
 
int64_t secondsFromNow () const
 Returns the number of seconds from the current time to the stored time. More...
 
void setToNow ()
 Set the time to the current time. More...
 
std::string toString () const
 Get the time/date as a string in the format: YYYY-MM-DD HH:MM:SS. More...
 

Private Attributes

time_t time_ = 0
 

Detailed Description

The generic time class for BoosterSeat. Uses UTC time.

Warning
This class has many issues related to time zones and DST. It's current purpose is just for simple time saving/loading in the giraffe project. This needs some serious work and testing before it can be used.

Constructor & Destructor Documentation

◆ Time()

bst::Time::Time ( bool  set_to_now = false)

Construct a new Time object. Defaults to the epoch.

Parameters
set_to_now- Set the time to the current time. Defaults to false.

References setToNow().

Here is the call graph for this function:

◆ ~Time()

bst::Time::~Time ( )
default

Member Function Documentation

◆ operator==()

bool bst::Time::operator== ( const Time rhs) const

References time_.

◆ operator!=()

bool bst::Time::operator!= ( const Time rhs) const

References time_.

◆ operator<()

bool bst::Time::operator< ( const Time rhs) const

References time_.

◆ operator<=()

bool bst::Time::operator<= ( const Time rhs) const

References time_.

◆ operator>()

bool bst::Time::operator> ( const Time rhs) const

References time_.

◆ operator>=()

bool bst::Time::operator>= ( const Time rhs) const

References time_.

◆ setToNow()

void bst::Time::setToNow ( )

Set the time to the current time.

References time_.

Referenced by Time(), and TEST().

Here is the caller graph for this function:

◆ toString()

std::string bst::Time::toString ( ) const

Get the time/date as a string in the format: YYYY-MM-DD HH:MM:SS.

Returns
std::string - The time/date string

References time_.

Referenced by TEST().

Here is the caller graph for this function:

◆ fromString()

bool bst::Time::fromString ( const std::string &  time_string)
Warning
This function is not cross platform. It will work on Linux.
Parameters
time_string- The time string to parse in the format: YYYY-MM-DD HH:MM:SS
Returns
true - The time string was parsed successfully
false - The time string was not parsed successfully

References time_.

Referenced by TEST().

Here is the caller graph for this function:

◆ getYear()

unsigned int bst::Time::getYear ( ) const

Get the Year.

Returns
unsigned int - The year

References time_.

Referenced by TEST().

Here is the caller graph for this function:

◆ getMonth()

unsigned int bst::Time::getMonth ( ) const

Get the Month (1 - 12)

Returns
unsigned int - The month

References time_.

Referenced by TEST().

Here is the caller graph for this function:

◆ getDay()

unsigned int bst::Time::getDay ( ) const

Get the Day.

Returns
unsigned int - The day

References time_.

Referenced by TEST().

Here is the caller graph for this function:

◆ getHour()

unsigned int bst::Time::getHour ( ) const

Get the Hour.

Returns
unsigned int - The hour

References time_.

Referenced by TEST().

Here is the caller graph for this function:

◆ getMinute()

unsigned int bst::Time::getMinute ( ) const

Get the Minute.

Returns
unsigned int - The minute

References time_.

Referenced by TEST().

Here is the caller graph for this function:

◆ getSecond()

unsigned int bst::Time::getSecond ( ) const

Get the Second.

Returns
unsigned int - The second

References time_.

Referenced by TEST().

Here is the caller graph for this function:

◆ getTimeType()

time_t bst::Time::getTimeType ( ) const
inline

References time_.

◆ secondsFromNow()

int64_t bst::Time::secondsFromNow ( ) const

Returns the number of seconds from the current time to the stored time.

Returns
int32_t Number of seconds from the current time. Negative if the stored time is in the past. Positive if the stored time is in the future.

References time_.

Referenced by TEST().

Here is the caller graph for this function:

Member Data Documentation

◆ time_