SBB Host
Host communication with the self balancing bike.
Loading...
Searching...
No Matches
Time Class Reference

A class to get system time. More...

#include <Timepp.h>

Public Member Functions

 Time ()
 Constructor. More...
 
void update_time ()
 Update the time. More...
 
int getYear (bool update=true)
 Get the current year. More...
 
int getMonth (bool update=true)
 Get the current month. More...
 
int getDay (bool update=true)
 Get the current month day. More...
 
int getHour (bool update=true)
 Get the current hour. More...
 
int getMin (bool update=true)
 Get the current minute. More...
 
int getSec (bool update=true)
 Get the current second. More...
 
int getData (char *str, size_t len, bool update=true)
 Get the current date-time. More...
 
std::string getData (bool update=true)
 Get the current data-time. More...
 

Private Attributes

struct tm tm
 Variable to store the current time. More...
 

Static Private Attributes

static constexpr int STR_LEN = 256
 String length to use as buffer. More...
 

Detailed Description

A class to get system time.

Class to get the system time in Windows and Linux. Actually this is just a wrapper for the localtime function of the time library.

Author
Stefano Lovato
Date
2022

Constructor & Destructor Documentation

◆ Time()

Time::Time ( )
inline

Constructor.

Constructor for Time object. It automatically updates the time

Member Function Documentation

◆ getData() [1/2]

std::string Time::getData ( bool  update = true)
inline

Get the current data-time.

Function to get the current data-time with format YYYY-MM-DD hh::mm::ss.

Parameters
updateA flag to update the time before getting the value (default is true).
Returns
The date-time as a string.

◆ getData() [2/2]

int Time::getData ( char *  str,
size_t  len,
bool  update = true 
)
inline

Get the current date-time.

Function to get the current date-time with format YYYY-MM-DD hh::mm::ss.

Parameters
strA pointer to char to store the string.
lenThe length of the char buffer.
updateA flag to update the time before getting the value (default is true).
Returns
The number of written char.

◆ getDay()

int Time::getDay ( bool  update = true)
inline

Get the current month day.

Function to get the current month day (from 1).

Parameters
updateA flag to update the time before getting the value (default is true).
Returns
The current month day.

◆ getHour()

int Time::getHour ( bool  update = true)
inline

Get the current hour.

Function to get the current hour.

Parameters
updateA flag to update the time before getting the value (default is true).
Returns
The current hour.

◆ getMin()

int Time::getMin ( bool  update = true)
inline

Get the current minute.

Function to get the current minute.

Parameters
updateA flag to update the time before getting the value (default is true).
Returns
The current minute.

◆ getMonth()

int Time::getMonth ( bool  update = true)
inline

Get the current month.

Function to get the current month.

Parameters
updateA flag to update the time before getting the value (default is true).
Returns
The current month.

◆ getSec()

int Time::getSec ( bool  update = true)
inline

Get the current second.

Function to get the current second.

Parameters
updateA flag to update the time before getting the value (default is true).
Returns
The current second.

◆ getYear()

int Time::getYear ( bool  update = true)
inline

Get the current year.

Function to get the current year.

Parameters
updateA flag to update the time before getting the value (default is true).
Returns
The current year.

◆ update_time()

void Time::update_time ( )
inline

Update the time.

Function to update the time stored in tm (to be called every time).

Member Data Documentation

◆ STR_LEN

constexpr int Time::STR_LEN = 256
staticconstexprprivate

String length to use as buffer.

◆ tm

struct tm Time::tm
private

Variable to store the current time.