Simple time class with milliseconds. More...
#include <time.hpp>
Public Types | |
| enum | tz_t { local , utc } |
Public Member Functions | |
| time () | |
| time (time_t t) | |
| time (const time_info &ti) | |
| time (int year, int month, int day, int hour, int min, int sec, long millis=0) | |
| time (const time &x)=default | |
| time (time &&x)=default | |
| time & | operator= (const time &x)=default |
| time & | operator= (time &&x)=default |
| ~time ()=default | |
| bool | operator== (const time &x) const |
| bool | operator!= (const time &x) const |
| bool | operator<= (const time &x) const |
| bool | operator< (const time &x) const |
| bool | operator> (const time &x) const |
| bool | operator>= (const time &x) const |
| time | to_utc () const |
| void | set (int year, int month, int day, int hour, int min, int sec, unsigned int millis) |
| void | set (const char *timestr, const char *format="%Y-%m-%d %H:%M%S") |
| void | set (time_t t, unsigned int millis) |
| void | set (const date &d) |
| void | set (const time_info &ti) |
| int | year () const |
| int | month () const |
| int | day () const |
| int | hour () const |
| int | minute () const |
| int | second () const |
| unsigned int | milli_second () const |
| time & | year (int y) |
| time & | month (int m) |
| time & | day (int d) |
| time & | hour (int h) |
| time & | minute (int m) |
| time & | second (int s) |
| time & | milli_second (int ms) |
| int | day_of_week () const |
| int | day_of_year () const |
| bool | is_leap_year () const |
| bool | is_daylight_saving () const |
| time_info | get_time_info () const |
| struct tm | get_tm () const |
| date | to_date () const |
Static Public Member Functions | |
| static time | now () |
| static bool | is_valid_time (int hour, int min, int sec, unsigned int millis) |
| static time | parse (const std::string &tstr, const char *format) |
Friends | |
| OOS_UTILS_API std::ostream & | operator<< (std::ostream &out, const time &x) |
Simple time class with milliseconds.
This class provides a simple interface for time representation. It is possible to create a time with millisecond precision.
Addition and subtraction of times is possible as well as parsing and formatting.
| enum matador::time::tz_t |
| matador::time::time | ( | ) |
Creates a new time with time now
|
explicit |
Create a time from time_t
| t | time_t value to create time from |
|
explicit |
Create a time from a timeval struct
| tv | timeval value to create time from |
| matador::time::time | ( | int | year, |
| int | month, | ||
| int | day, | ||
| int | hour, | ||
| int | min, | ||
| int | sec, | ||
| long | millis = 0 |
||
| ) |
Create a time from discret values
| year | Year value of time |
| month | Month value of time |
| day | Day value of time |
| hour | Hour part of time |
| min | Minute part of time |
| sec | Second part of time |
| millis | Milliseconds of time (default is zero) |
|
default |
Create a time from another time
| x | Other time object to be initialized from |
|
default |
Copy move from another time
| x | Other time object to be move from |
|
default |
Destroy time
| int matador::time::day | ( | ) | const |
Return the day of the time.
| time & matador::time::day | ( | int | d | ) |
Sets the day part of the time and returns the time object.
| d | The day part to set. |
| int matador::time::day_of_week | ( | ) | const |
Returns the day of week number. By now the week starts with monday which is index 0 (zero).
| int matador::time::day_of_year | ( | ) | const |
Returns the day of the year number. First day of the year is number one (1).
| time_info matador::time::get_time_info | ( | ) | const |
Returns the underlying timeval struct representing the time.
| struct tm matador::time::get_tm | ( | ) | const |
Returns the time as struct tm representing the time without milli seconds
| int matador::time::hour | ( | ) | const |
Return the hour of the time.
| time & matador::time::hour | ( | int | h | ) |
Sets the hour part of the time and returns the time object.
| h | The hour part to set. |
| bool matador::time::is_daylight_saving | ( | ) | const |
Returns true if time is in daylight saving range which depends one the country.
| bool matador::time::is_leap_year | ( | ) | const |
Returns true if times year is a leap year.
|
static |
Checks if given time parts are valid
0 <= hour < 24 0 <= minutes < 60 0 <= seconds < 60 0 <= milliseconds < 1000
| hour | Hour to check |
| min | Minute to check |
| sec | Seconds to check |
| millis | Milliseconds to check |
| unsigned int matador::time::milli_second | ( | ) | const |
Return the milliseconds of the time.
| time & matador::time::milli_second | ( | int | ms | ) |
Sets the millisecond part of the time and returns the time object.
| ms | The millisecond part to set. |
| int matador::time::minute | ( | ) | const |
Return the minute of the time.
| time & matador::time::minute | ( | int | m | ) |
Sets the minute part of the time and returns the time object.
| m | The minute part to set. |
| int matador::time::month | ( | ) | const |
Return the month of the time.
| time & matador::time::month | ( | int | m | ) |
Sets the month part of the time and returns the time object.
| m | The month part to set. |
|
static |
Gets current time.
| bool matador::time::operator!= | ( | const time & | x | ) | const |
Check if two times are not equal
| x | Time object to compare with |
| bool matador::time::operator< | ( | const time & | x | ) | const |
Check if time is less than other time
| x | Time object to compare with |
| bool matador::time::operator<= | ( | const time & | x | ) | const |
Check if time is less equal than other time
| x | Time object to compare with |
Assign time from another time object
| x | Assign time from this time object |
Assignment move from another time
| x | Assign move time from this time object |
| bool matador::time::operator== | ( | const time & | x | ) | const |
Check if two times are equal
| x | Time object to compare with |
| bool matador::time::operator> | ( | const time & | x | ) | const |
Check if time is greater than other time
| x | Time object to compare with |
| bool matador::time::operator>= | ( | const time & | x | ) | const |
Check if time is greater equal than other time
| x | Time object to compare with |
|
static |
Parse a given time string with a valid format and return a corresponding time object.
| tstr | Time string. |
| format | Time strings format. |
| int matador::time::second | ( | ) | const |
Return the seconds of the time.
| time & matador::time::second | ( | int | s | ) |
Sets the second part of the time and returns the time object.
| s | The second part to set. |
| void matador::time::set | ( | const char * | timestr, |
| const char * | format = "%Y-%m-%d %H:%M%S" |
||
| ) |
Sets the date from a given date/time string and a format string
| timestr | The date/time string to parse |
| format | The format to use for parsing |
| void matador::time::set | ( | const date & | d | ) |
Sets the time from a date. The hour, minute, seconds and millisecond part is set to zero
| d | The date to set. |
| void matador::time::set | ( | const time_info & | ti | ) |
Sets the time from a given timeval object.
| tv | Timeval object to set the time from. |
| void matador::time::set | ( | int | year, |
| int | month, | ||
| int | day, | ||
| int | hour, | ||
| int | min, | ||
| int | sec, | ||
| unsigned int | millis | ||
| ) |
Sets time by its parts.
| year | The year part of the time. |
| month | The month part of the time. |
| day | The day part of the time. |
| hour | The hour part of the time. |
| min | The minute part of the time. |
| sec | The seconds part of the time. |
| millis | The milliseconds part of the time. |
| void matador::time::set | ( | time_t | t, |
| unsigned int | millis | ||
| ) |
Sets the time from a given time_t and milliseconds
| t | The time_t to set. |
| millis | The milliseconds to set. |
| date matador::time::to_date | ( | ) | const |
Converts and returns the date part of the time to a date objects
| int matador::time::year | ( | ) | const |
Return the year of the time.
| time & matador::time::year | ( | int | y | ) |
Sets the year part of the time and returns the time object.
| y | The year part to set. |
|
friend |
Writes the time to an std::ostream in ISO8601 format
| out | The stream to write to. |
| x | The time object to be printed |