Ocean
Ocean::DateTime Class Reference

This class provides basic functionalities for date and time handling. More...

Static Public Member Functions

static double timestamp ()
 Returns the seconds since 1970.01.01 00::00::00 to current UTC time. More...
 
static long long microseconds ()
 Returns the microseconds since 1970.01.01 00::00::00 to current UTC time. More...
 
static std::string string (const bool addMilliseconds=false)
 Returns the string of the UTC date and time. More...
 
static std::string string (const double timestamp, const bool addMilliseconds=false)
 Returns the string of a given unix timestamp. More...
 
static std::string stringDate (const char delimiter='.')
 Returns the string of the UTC date. More...
 
static std::string stringDate (const double timestamp, const bool nameMonths=false)
 Returns the string of a given unix timestamp. More...
 
static std::string stringTime (const bool addMilliseconds=false, const char delimiter='-')
 Returns the string of the UTC time. More...
 
static std::string stringTime (const double timestamp, const bool addMilliseconds=false, const char delimiter='-')
 Returns the string of a given unix timestamp. More...
 
static double localTimestamp ()
 Returns the seconds since 1970.01.01 00::00::00 to current local time. More...
 
static long long localMicroseconds ()
 Returns the microseconds since 1970.01.01 00::00::00 to current local time. More...
 
static std::string localString ()
 Returns the string of the local date and time. More...
 
static std::string localStringDate (const char delimiter='.')
 Returns the string of the local date. More...
 
static double date2timestamp (const unsigned int year, const unsigned int month, const unsigned int day, const unsigned int hour, const unsigned int minute, const unsigned int second, const unsigned int millisecond=0u)
 Converts a date to the seconds since 1970.01.01 00:00:00. More...
 
static void timestamp2date (const double timestamp, unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &second, unsigned int *millisecond=nullptr)
 Converts a unix timestamp (the seconds since 1970.01.01 00:00:00) to a date. More...
 
static std::string seconds2string (const double totalSeconds, const bool addDescription, const bool addMilliseconds=false)
 Converts value of seconds to a time string showing the hours, minutes and seconds. More...
 
static std::string localStringTime (const bool addMilliseconds=false, const char delimiter=':')
 Returns the string of the local time. More...
 
static unsigned int isLeapYear (const unsigned int year)
 Returns whether a given year is a leap year. More...
 
static bool isDateValid (const unsigned int year, const unsigned int month, const unsigned int day)
 Returns whether a given date is a valid date (e.g., in no leap years the 29th February is an invalid date) More...
 

Detailed Description

This class provides basic functionalities for date and time handling.


All functions are available for UTC and local time.

Member Function Documentation

◆ date2timestamp()

static double Ocean::DateTime::date2timestamp ( const unsigned int  year,
const unsigned int  month,
const unsigned int  day,
const unsigned int  hour,
const unsigned int  minute,
const unsigned int  second,
const unsigned int  millisecond = 0u 
)
static

Converts a date to the seconds since 1970.01.01 00:00:00.

Parameters
yearThe year, with range [1970, 2037)
monthThe month, with range [1, 12]
dayThe day, with range [1, 31]
hourThe hour, with range [0, 23]
minuteThe minute, with range [0, 59]
secondThe second, with range [0, 59]
millisecondThe millisecond, with range [0, 999]
Returns
The unix timestamp, -1 if the given date is invalid

◆ isDateValid()

static bool Ocean::DateTime::isDateValid ( const unsigned int  year,
const unsigned int  month,
const unsigned int  day 
)
static

Returns whether a given date is a valid date (e.g., in no leap years the 29th February is an invalid date)

Parameters
yearThe year of the date, with range [0, infinity)
monthThe month of the date, with range [1, 12]
dayThe day of the date, with range [1, 31]
Returns
True, if so

◆ isLeapYear()

unsigned int Ocean::DateTime::isLeapYear ( const unsigned int  year)
inlinestatic

Returns whether a given year is a leap year.

Parameters
yearThe year to check

◆ localMicroseconds()

static long long Ocean::DateTime::localMicroseconds ( )
static

Returns the microseconds since 1970.01.01 00::00::00 to current local time.

Returns
Microseconds

◆ localString()

static std::string Ocean::DateTime::localString ( )
static

Returns the string of the local date and time.

Returns
Date and time string

◆ localStringDate()

static std::string Ocean::DateTime::localStringDate ( const char  delimiter = '.')
static

Returns the string of the local date.

Parameters
delimiterThe delimiter to be used
Returns
Date string of local date, with format YYYY.MM.DD, if delimiter is '.'

◆ localStringTime()

static std::string Ocean::DateTime::localStringTime ( const bool  addMilliseconds = false,
const char  delimiter = ':' 
)
static

Returns the string of the local time.

The resulting string has the following format: HH:MM:SS, or HH:MM:SS:mmmm if the milliseconds are added.

Parameters
addMillisecondsTrue, to add the milliseconds to the string
delimiterThe delimiter to be used
Returns
Time string of local time

◆ localTimestamp()

static double Ocean::DateTime::localTimestamp ( )
static

Returns the seconds since 1970.01.01 00::00::00 to current local time.

Returns
Seconds

◆ microseconds()

static long long Ocean::DateTime::microseconds ( )
static

Returns the microseconds since 1970.01.01 00::00::00 to current UTC time.

Returns
Microseconds

◆ seconds2string()

static std::string Ocean::DateTime::seconds2string ( const double  totalSeconds,
const bool  addDescription,
const bool  addMilliseconds = false 
)
static

Converts value of seconds to a time string showing the hours, minutes and seconds.

The resulting string has the following format: HH:MM:SS, or HH:MM:SS:mmmm if the milliseconds are added; or H hours, M minutes, S seconds or H hours, M minutes, S seconds, m milliseconds if the description is added.

Parameters
totalSecondsThe number of seconds to convert, with range [0, infinity)
addDescriptionTrue, to add the description text to the string
addMillisecondsTrue, to add the milliseconds to the string
Returns
Time string of local time

◆ string() [1/2]

static std::string Ocean::DateTime::string ( const bool  addMilliseconds = false)
static

Returns the string of the UTC date and time.

Parameters
addMillisecondsTrue, to add the milliseconds to the string
Returns
Date and time string

◆ string() [2/2]

static std::string Ocean::DateTime::string ( const double  timestamp,
const bool  addMilliseconds = false 
)
static

Returns the string of a given unix timestamp.

Parameters
timestampThe unix timestamp (seconds since 1970.01.01 00:00:00) to be converted, with range [0, infinity)
addMillisecondsTrue, to add the milliseconds to the string
Returns
Date and time string

◆ stringDate() [1/2]

static std::string Ocean::DateTime::stringDate ( const char  delimiter = '.')
static

Returns the string of the UTC date.

Parameters
delimiterThe delimiter to be used
Returns
Date string, with pattern YYYY.MM.DD, if delimiter is '.'

◆ stringDate() [2/2]

static std::string Ocean::DateTime::stringDate ( const double  timestamp,
const bool  nameMonths = false 
)
static

Returns the string of a given unix timestamp.

Parameters
timestampThe unix timestamp (seconds since 1970.01.01 00:00:00) to be converted, with range [0, infinity)
nameMonthsTrue, to receive a date with named months; False, to receive a date with digits only (but with constant length)
Returns
Date string, with pattern YYYY.MM.DD (2016.08.05) for nameMonths=false; or MMMMMMMMMM D/DD, YYYY (May 5, 2016) for nameMonths=true

◆ stringTime() [1/2]

static std::string Ocean::DateTime::stringTime ( const bool  addMilliseconds = false,
const char  delimiter = '-' 
)
static

Returns the string of the UTC time.

The resulting string has the following format: HH-MM-SS, or HH-MM-SS-mmmm if the milliseconds are added.

Parameters
addMillisecondsTrue, to add the milliseconds to the string
delimiterThe delimiter to be used
Returns
Time string of UTC time

◆ stringTime() [2/2]

static std::string Ocean::DateTime::stringTime ( const double  timestamp,
const bool  addMilliseconds = false,
const char  delimiter = '-' 
)
static

Returns the string of a given unix timestamp.

The resulting string has the following format: HH-MM-SS, or HH-MM-SS-mmmm if the milliseconds are added.

Parameters
timestampThe unix timestamp (seconds since 1970.01.01 00:00:00) to be converted, with range [0, infinity)
addMillisecondsTrue, to add the milliseconds to the string
delimiterThe delimiter to be used
Returns
Time string of the UTC time

◆ timestamp()

static double Ocean::DateTime::timestamp ( )
static

Returns the seconds since 1970.01.01 00::00::00 to current UTC time.

Returns
Seconds

◆ timestamp2date()

static void Ocean::DateTime::timestamp2date ( const double  timestamp,
unsigned int &  year,
unsigned int &  month,
unsigned int &  day,
unsigned int &  hour,
unsigned int &  minute,
unsigned int &  second,
unsigned int *  millisecond = nullptr 
)
static

Converts a unix timestamp (the seconds since 1970.01.01 00:00:00) to a date.

Parameters
timestampThe unix timestamp to convert
yearThe resulting year, with range [1970, 2037)
monthThe resulting month, with range [1, 12]
dayThe resulting date, with range [1, 31]
hourThe resulting hour, with range [0, 23]
minuteThe resulting minute, with range [0, 59]
secondThe resulting second, with range [0, 59]
millisecondOptional resulting millisecond, with range [0, 999]

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