radarlib 1.4.6
Radar::timeutils Namespace Reference

Functions about times and dates. More...

Functions

time_t getUTC ()
 Get the current UTC time from the system.
 
time_t mktime (int year, int month, int day)
 Create a time from a date.
 
time_t mktime (int year, int month, int day, int hour, int min, int sec)
 Create a time from a date.
 
double mktime (int year, int month, int day, int hour, int min, int sec, int msec)
 Create a time from a date.
 
bool isValidDate (int year, int month, int day)
 Check if the specified date is a valid date.
 
bool isValidTime (int hour, int min, int sec)
 Check if the specified time is a valid date.
 
void splitYMD (time_t absolute, int &year, int &month, int &day)
 Extract date informations from a time_t value.
 
void splitYMD (double absolute, int &year, int &month, int &day)
 Extract date informations from a double value.
 
void splitHMS (time_t absolute, int &hour, int &min, int &sec)
 Extract day time informations from a time_t value.
 
void splitHMS (double absolute, int &hour, int &min, int &sec, int &msec)
 Extract day time informations from a double value.
 
void splitYMDHMS (time_t absolute, int &year, int &month, int &day, int &hour, int &min, int &sec)
 Extract date and day time informations from a time_t value.
 
void splitYMDHMS (double absolute, int &year, int &month, int &day, int &hour, int &min, int &sec, int &msec)
 Extract date and day time informations from a double value.
 
std::string absoluteToString (time_t value)
 , const char* fmt)
 
std::string absoluteToString (double value, bool allowNAN)
 Convert an double value representing an absolute time_t value with milliseconds.
 
time_t parseYYYYMMDDHHMMSS (const std::string &str)
 Convert a string to a time_t value.
 
time_t toEpoch (double absolute)
 Reduce a double value to a time_t value, truncating the milliseconds.
 
time_t toEpoch (float absolute)
 Reduce a float value to a time_t value, truncating the milliseconds.
 
time_t extractDate (time_t absolute)
 Extract the date from a time_t value to a new time_t value.
 
double extractDate (double absolute)
 Extract the date from a double value to a new double value.
 
time_t extractTime (time_t absolute)
 Extract the day time from a time_t value to a new time_t value.
 
double extractTime (double absolute)
 Extract the day time from a double value to a new double value.
 
std::string dayTimeToStr (time_t value)
 Convert a day time to a string.
 
std::string dayTimeToStr (double value)
 Convert a day time with milliseconds to a string.
 
void convertYday (int year, int yday, int &month, int &day)
 Convert a year day to the corresponding month and day number.
 
time_t convertYday (int year, int yday)
 Convert a year day to the corresponding time_t value.
 
int mkYday (int year, int month, int day)
 Calculate the year day from a date.
 

Detailed Description

Functions about times and dates.

Function Documentation

◆ getUTC()

RADAR_API time_t Radar::timeutils::getUTC ( )

Get the current UTC time from the system.

Get the current UTC time from the system as a time_t value

Returns
A time_t value
Examples
create_odim_object.cpp.

◆ mktime() [1/3]

RADAR_API time_t Radar::timeutils::mktime ( int  year,
int  month,
int  day 
)

Create a time from a date.

Create a time_t value from a date. The time_t value will be aligned to the hour 00:00:00 of the day specified

Parameters
yearthe year to use. It must be >= 1970
monththe month to use
daythe day to use
Returns
The time_t value representing the date specified
Exceptions
std::invalid_argumentIf the date is not a valid date
Examples
create_polar_volume.cpp.

◆ mktime() [2/3]

RADAR_API time_t Radar::timeutils::mktime ( int  year,
int  month,
int  day,
int  hour,
int  min,
int  sec 
)

Create a time from a date.

Create a time_t value from a date and a time

Parameters
yearthe year to use. It must be >= 1970
monththe month to use
daythe day to use
hourthe hour to use
minthe minutes to use
secthe seconds to use
Returns
The time_t value representing the date specified
Exceptions
std::invalid_argumentIf the values are out of range

◆ mktime() [3/3]

RADAR_API double Radar::timeutils::mktime ( int  year,
int  month,
int  day,
int  hour,
int  min,
int  sec,
int  msec 
)

Create a time from a date.

Create a time_t value from a date and a time

Parameters
yearthe year to use. It must be >= 1970
monththe month to use
daythe day to use
hourthe hour to use
minthe minutes to use
secthe seconds to use
msecthe milliseconds to use
Returns
The time_t value representing the date specified
Exceptions
std::invalid_argumentIf the values are out of range

◆ isValidDate()

RADAR_API bool Radar::timeutils::isValidDate ( int  year,
int  month,
int  day 
)

Check if the specified date is a valid date.

Check if the specified date is a valid date

Parameters
yearthe year to use. It must be >= 1970
monththe month to use
daythe day to use
Returns
True if the date is valid, false otherwise

◆ isValidTime()

RADAR_API bool Radar::timeutils::isValidTime ( int  hour,
int  min,
int  sec 
)

Check if the specified time is a valid date.

Check if the specified time is a valid date

Parameters
hourthe hour to use. It must be >= 1970
minthe min to use
secthe sec to use
Returns
True if the time is valid, false otherwise

◆ splitYMD() [1/2]

RADAR_API void Radar::timeutils::splitYMD ( time_t  absolute,
int &  year,
int &  month,
int &  day 
)

Extract date informations from a time_t value.

Extract date informations from the given time_t value

Parameters
absolutethe absolute time_t value
yeara reference to a integer that will store the extracted year number
montha reference to a integer that will store the extracted month number
daya reference to a integer that will store the extracted day number

◆ splitYMD() [2/2]

RADAR_API void Radar::timeutils::splitYMD ( double  absolute,
int &  year,
int &  month,
int &  day 
)

Extract date informations from a double value.

Extract date informations from the given double value representing an absolute time_t value with milliseconds

Parameters
absolutethe absolute time_t value
yeara reference to a integer that will store the extracted year number
montha reference to a integer that will store the extracted month number
daya reference to a integer that will store the extracted day number

◆ splitHMS() [1/2]

RADAR_API void Radar::timeutils::splitHMS ( time_t  absolute,
int &  hour,
int &  min,
int &  sec 
)

Extract day time informations from a time_t value.

Extract day time informations from the given time_t value

Parameters
absolutethe absolute time_t value
houra reference to a integer that will store the extracted hour number
mina reference to a integer that will store the extracted minutes number
seca reference to a integer that will store the extracted seconds number

◆ splitHMS() [2/2]

RADAR_API void Radar::timeutils::splitHMS ( double  absolute,
int &  hour,
int &  min,
int &  sec,
int &  msec 
)

Extract day time informations from a double value.

Extract day time informations from the given double value representing an absolute time_t value with milliseconds

Parameters
absolutethe absolute time_t value
houra reference to a integer that will store the extracted hour number
mina reference to a integer that will store the extracted minutes number
seca reference to a integer that will store the extracted seconds number
mseca reference to a integer that will store the extracted milliseconds number

◆ splitYMDHMS() [1/2]

RADAR_API void Radar::timeutils::splitYMDHMS ( time_t  absolute,
int &  year,
int &  month,
int &  day,
int &  hour,
int &  min,
int &  sec 
)

Extract date and day time informations from a time_t value.

Extract date and day time informations from the given time_t value

Parameters
absolutethe absolute time_t value
yeara reference to a integer that will store the extracted hour number
montha reference to a integer that will store the extracted minutes number
daya reference to a integer that will store the extracted seconds number
houra reference to a integer that will store the extracted hour number
mina reference to a integer that will store the extracted minutes number
seca reference to a integer that will store the extracted seconds number

◆ splitYMDHMS() [2/2]

RADAR_API void Radar::timeutils::splitYMDHMS ( double  absolute,
int &  year,
int &  month,
int &  day,
int &  hour,
int &  min,
int &  sec,
int &  msec 
)

Extract date and day time informations from a double value.

Extract date and day time informations from the given double value representing an absolute time_t value with milliseconds

Parameters
absolutethe absolute time_t value
yeara reference to a integer that will store the extracted hour number
montha reference to a integer that will store the extracted minutes number
daya reference to a integer that will store the extracted seconds number
houra reference to a integer that will store the extracted hour number
mina reference to a integer that will store the extracted minutes number
seca reference to a integer that will store the extracted seconds number
mseca reference to a integer that will store the extracted milliseconds number

◆ absoluteToString() [1/2]

RADAR_API std::string Radar::timeutils::absoluteToString ( time_t  value)

, const char* fmt)

Convert an absolute time_t value to a string.

Convert an absolute time_t value to a string with format 'YYYY-MM-DD hh:mm:ss'

Parameters
valuethe time_t value to convert
Returns
the formated string
Examples
image-visitor.cpp.

◆ absoluteToString() [2/2]

RADAR_API std::string Radar::timeutils::absoluteToString ( double  value,
bool  allowNAN 
)

Convert an double value representing an absolute time_t value with milliseconds.

Convert an absolute time_t value to a string with format 'YYYY-MM-DD hh:mm:ss.msec'

Parameters
valuethe time_t value to convert
allowNANif the value is NAN returns "0000-00-00 00:00:00" instead of throwing an exception
Returns
the formated string
Exceptions
std::invalid_argumentIf the value cannot be converted

◆ parseYYYYMMDDHHMMSS()

RADAR_API time_t Radar::timeutils::parseYYYYMMDDHHMMSS ( const std::string &  str)

Convert a string to a time_t value.

Convert a string to a time_t value. The string must be formated as 'YYYY-MM-DD hh:mm:ss'

Parameters
strthe string to convert
Returns
the formated string
Exceptions
std::invalid_argumentIf the string cannot be converted
Remarks
This function will try to parse the given string with diffrent type of char separator (-,:, spaces etc.)

◆ toEpoch() [1/2]

RADAR_API time_t Radar::timeutils::toEpoch ( double  absolute)

Reduce a double value to a time_t value, truncating the milliseconds.

◆ toEpoch() [2/2]

RADAR_API time_t Radar::timeutils::toEpoch ( float  absolute)

Reduce a float value to a time_t value, truncating the milliseconds.

◆ extractDate() [1/2]

RADAR_API time_t Radar::timeutils::extractDate ( time_t  absolute)

Extract the date from a time_t value to a new time_t value.

Extract the date from a time_t value to a new time_t value. Day time informations will be set to 00:00:00

Parameters
absolutethe absolute time to use
Returns
the date extracted

◆ extractDate() [2/2]

RADAR_API double Radar::timeutils::extractDate ( double  absolute)

Extract the date from a double value to a new double value.

Extract the date from a double value to a new time_t value. Day time informations will be set to 00:00:00

Parameters
absolutethe absolute time to use
Returns
the date extracted

◆ extractTime() [1/2]

RADAR_API time_t Radar::timeutils::extractTime ( time_t  absolute)

Extract the day time from a time_t value to a new time_t value.

Extract the day time from a time_t value to a new time_t value. The result value range is between 0 and 60*60*24 minutes

Parameters
absolutethe absolute time to use
Returns
the day time extracted

◆ extractTime() [2/2]

RADAR_API double Radar::timeutils::extractTime ( double  absolute)

Extract the day time from a double value to a new double value.

Extract the day time from a time_t value to a new time_t value. The result value range is between 0 and 60*60*24 minutes

Parameters
absolutethe absolute time to use
Returns
the day time extracted

◆ dayTimeToStr() [1/2]

RADAR_API std::string Radar::timeutils::dayTimeToStr ( time_t  value)

Convert a day time to a string.

Convert a day time to string formated as 'HH:MM:SS'

Parameters
valuethe day time as a time_t value
Returns
the formatted string

◆ dayTimeToStr() [2/2]

RADAR_API std::string Radar::timeutils::dayTimeToStr ( double  value)

Convert a day time with milliseconds to a string.

Convert a day time to string formated as 'HH:MM:SS.msec'

Parameters
valuethe day time as a double value
Returns
the formatted string

◆ convertYday() [1/2]

RADAR_API void Radar::timeutils::convertYday ( int  year,
int  yday,
int &  month,
int &  day 
)

Convert a year day to the corresponding month and day number.

Convert a year day to the corresponding month and day number

Parameters
yearthe year to use
ydaythe year day to use (from 1 to 365/366)
montha reference to an integer that will store the month number (from 1 to 12)
daya reference to an integer that will store the day number (from 1 to 31)
Exceptions
std::invalid_argumentif the year or yday values are not valid

◆ convertYday() [2/2]

RADAR_API time_t Radar::timeutils::convertYday ( int  year,
int  yday 
)

Convert a year day to the corresponding time_t value.

Convert a year day to the corresponding time_t value

Parameters
yearthe year to use
ydaythe year day to use (from 1 to 365/366)
Exceptions
std::invalid_argumentif the year or yday values are not valid

◆ mkYday()

RADAR_API int Radar::timeutils::mkYday ( int  year,
int  month,
int  day 
)

Calculate the year day from a date.

Calculate the year day from a date

Parameters
yearthe year value (must be >= 1970)
monththe month value (from 1 to 12)
daythe day day (from 1 to 365/366)
Exceptions
std::invalid_argumentif the year or yday values are not valid