Skip to content

DateTimeString

class DateTimeString

This class expresses a valid date and time information in the form of a char string. To be a valid date and time char string, it must respect: - ISO-8601:2000 Second Edition definition (docs available at http://www.qsl.net/g1smd/isopdf.htm) - Subset (of ISO-8601) defined as Karabo date and time API * Compact version: yyyymmddThhmmss[.|,]ffffff[Z|z|±hhmm] (max. digits for ffffff is 18) * Extended version: yyyy-mm-ddThh🇲🇲ss[.|,]ffffff[Z|z|±hh:mm] (max. digits for ffffff is 18)

The default constructor initializes a DateTimeString object with the Epoch values ("19700101T000000Z").

Functions

Name Description
DateTimeString Constructor without parameters, that creates a instance with epoch Timestamp ("19700101T000000Z")
DateTimeString Constructor from string timePoint : String that represents a complete and valid date format using Karabo agreed ISO-8601 subset API
DateTimeString Constructor from string inputDateStr : String that represents the date part of the Karabo agreed ISO-8601 subset API inputTimeStr : String that represents the time part of the Karabo agreed ISO-8601 subset API inputFractionSecondStr : String that represents the fractional part of the Karabo agreed ISO-8601 subset API inputTimeZoneStr : String that represents the time zone part of the Karabo agreed ISO-8601 subset API
getDate Get string that represents the date part of the Karabo agreed ISO-8601 subset API (i.e. "2013-01-20") Return : string
getTime Get string that represents the time part of the Karabo agreed ISO-8601 subset API (i.e. "20:30:00") Return : string
getFractionalSeconds Get string or unsigned long long that represents the fractional part of the Karabo agreed ISO-8601 subset API (i.e. "123456") Return : string
getTimeZone Get string that represents the time zone part of the Karabo agreed ISO-8601 subset API (i.e. "Z") Return : string
getDateTime Get string that represents the date and time part of the Karabo agreed ISO-8601 subset API (i.e. "2013-01-20T20:30:00") Return : string
isStringValidIso8601 Validates if a string representing a timestamp is valid according to ISO-8601 definition timePoint : String that represents a Timestamp Return : boolean (True is string is valid, False otherwise)
isStringValidIso8601TimeZone Validates if a string representing a time zone is valid according to ISO-8601 definition iso8601TimeZone : String that represents a Time Zone (i.e. "+01:00" or "-07:00") Return : boolean (True is string is valid, False otherwise)
isStringKaraboValidIso8601 Validates if a string representing a timestamp is valid according to Karabo agreed ISO-8601 subset API definition Some examples: => Extended strings: - 1985-01-20T23:20:50 - 1985-01-20T23:20:50,123 - 1985-01-20T23:20:50.123 - 1985-01-20T23:20:50.123z - 1985-01-20T23:20:50.123Z - 1985-01-20T23:20:50z - 1985-01-20T23:20:50Z - 1985-01-20T23:20:50+00:00 - 1985-01-20T23:20:50-07:00 => Compact strings: - 19850120T232050 - 19850120T232050,123 - 19850120T232050.123 - 19850120T232050.123z - 19850120T232050.123Z - 19850120T232050z - 19850120T232050Z - 19850120T232050+0000 - 19850120T232050-0700 timePoint : String that represents a Timestamp Return : boolean (True is string is valid, False otherwise)
getSecondsSinceEpoch Returns the number of seconds elapsed since epoch for this object Return : unsigned long long (Seconds elapsed since Epoch)
fractionalSecondToString Converts a fractional second value into it's value with a smaller precision Because fractional seconds are received as an UNSIGNED LONG LONG, this function assumes the algarisms are the right most algarisms.
fractionalStringToAttoFractionalString Converts a STRING fractional second value into it's value in ATTOSEC precision Because fractional seconds are received as a STRING, this function assumes the algarisms are the left most algarisms.
getTimeDurationFromTimeZone Split an ISO-8601 valid Time Zone iso8601TimeZone : String that represents a Time Zone (i.e. "Z" or "+01:00" or "-07:00") [Default: "Z"] Return : Hash containing the Time Zone information in three different keys (("timeZoneSignal"), ("timeZoneHours"), ("timeZoneMinutes"))
ptimeToSecondsSinceEpoch Convert a specific clock time point to the number of seconds since epoch (1970-Jan-1 00:00:00) tp : specific (std::chrono::system_clock) time point Return : number of seconds since epoch
iso8601KaraboApiStringToDateTimeString Creates an DateTimeString from an ISO-8601 formatted string (string must be a complete and valid timestamp using Karabo agreed ISO-8601 subset API) timePoint : ISO 8601 formatted string (see formats locale to more information) Return : DateTimeString object

Function Details

DateTimeString

DateTimeString()

Constructor without parameters, that creates a instance with epoch Timestamp ("19700101T000000Z")

DateTimeString(const std::string& timePoint)

Constructor from string

timePoint : String that represents a complete and valid date format using Karabo agreed ISO-8601 subset API

DateTimeString(const std::string& inputDate, const std::string& inputTime, const std::string& inputFractionSecond, const std::string& inputTimeZone)

Constructor from string

inputDateStr : String that represents the date part of the Karabo agreed ISO-8601 subset API

inputTimeStr : String that represents the time part of the Karabo agreed ISO-8601 subset API

inputFractionSecondStr : String that represents the fractional part of the Karabo agreed ISO-8601 subset API

inputTimeZoneStr : String that represents the time zone part of the Karabo agreed ISO-8601 subset API

fractionalSecondToString

static const std::string fractionalSecondToString(const TIME_UNITS precision = MICROSEC, const unsigned long long fractionalSeconds = 0, bool skipDot = false)

Converts a fractional second value into it's value with a smaller precision Because fractional seconds are received as an UNSIGNED LONG LONG, this function assumes the algarisms are the right most algarisms. Due to this reason, if there are missing algarisms to perform the desired precision resolution, zeros will be added to this left of the fractional seconds number received.

precision : - Indicates the precision of the fractional seconds (e.g. MILLISEC, MICROSEC, NANOSEC, PICOSEC, FEMTOSEC, ATTOSEC) [Default: MICROSEC]

fractionalSeconds : - Fractional seconds to be return with the correct desired precision

skipDot : - if true, skip leading dot "." in result [Default: false]

Return : String started with a "." (dot) (except skipDot is true) and followed by the fractional second till the desired precision

fractionalStringToAttoFractionalString

static const std::string fractionalStringToAttoFractionalString(const std::string& fractionalSeconds)

Converts a STRING fractional second value into it's value in ATTOSEC precision Because fractional seconds are received as a STRING, this function assumes the algarisms are the left most algarisms. Due to this reason, if there are missing algarisms to perform ATTOSEC resolution, zeros will be added to this right of the fractional seconds number received.

fractionalSeconds : - Fractional seconds to be return with ATTOSEC precision

Return : String started with a "." (dot) and followed by the fractional second till the desired precision

getDate

inline const std::string& getDate() const

Get string that represents the date part of the Karabo agreed ISO-8601 subset API (i.e. "2013-01-20")

Return : string

getDateTime

inline const std::string& getDateTime() const

Get string that represents the date and time part of the Karabo agreed ISO-8601 subset API (i.e. "2013-01-20T20:30:00")

Return : string

getFractionalSeconds

template <typename T> inline const T getFractionalSeconds() const

Get string or unsigned long long that represents the fractional part of the Karabo agreed ISO-8601 subset API (i.e. "123456")

Return : string

getSecondsSinceEpoch

const unsigned long long getSecondsSinceEpoch()

Returns the number of seconds elapsed since epoch for this object

Return : unsigned long long (Seconds elapsed since Epoch)

getTime

inline const std::string& getTime() const

Get string that represents the time part of the Karabo agreed ISO-8601 subset API (i.e. "20:30:00")

Return : string

getTimeDurationFromTimeZone

static const karabo::data::Hash getTimeDurationFromTimeZone(const std::string& iso8601TimeZone = "Z")

Split an ISO-8601 valid Time Zone

iso8601TimeZone : String that represents a Time Zone (i.e. "Z" or "+01:00" or "-07:00") [Default: "Z"]

Return : Hash containing the Time Zone information in three different keys (("timeZoneSignal"), ("timeZoneHours"), ("timeZoneMinutes"))

getTimeZone

inline const std::string& getTimeZone() const

Get string that represents the time zone part of the Karabo agreed ISO-8601 subset API (i.e. "Z")

Return : string

isStringKaraboValidIso8601

static const bool isStringKaraboValidIso8601(const std::string& timePoint)

Validates if a string representing a timestamp is valid according to Karabo agreed ISO-8601 subset API definition Some examples: => Extended strings: - 1985-01-20T23:20:50 - 1985-01-20T23:20:50,123 - 1985-01-20T23:20:50.123 - 1985-01-20T23:20:50.123z - 1985-01-20T23:20:50.123Z - 1985-01-20T23:20:50z - 1985-01-20T23:20:50Z - 1985-01-20T23:20:50+00:00 - 1985-01-20T23:20:50-07:00 => Compact strings: - 19850120T232050 - 19850120T232050,123 - 19850120T232050.123 - 19850120T232050.123z - 19850120T232050.123Z - 19850120T232050z - 19850120T232050Z - 19850120T232050+0000 - 19850120T232050-0700

timePoint : String that represents a Timestamp

Return : boolean (True is string is valid, False otherwise)

isStringValidIso8601

static const bool isStringValidIso8601(const std::string& timePoint)

Validates if a string representing a timestamp is valid according to ISO-8601 definition

timePoint : String that represents a Timestamp

Return : boolean (True is string is valid, False otherwise)

isStringValidIso8601TimeZone

static const bool isStringValidIso8601TimeZone(const std::string& iso8601TimeZone)

Validates if a string representing a time zone is valid according to ISO-8601 definition

iso8601TimeZone : String that represents a Time Zone (i.e. "+01:00" or "-07:00")

Return : boolean (True is string is valid, False otherwise)

iso8601KaraboApiStringToDateTimeString

static const DateTimeString iso8601KaraboApiStringToDateTimeString(const std::string& timePoint)

Creates an DateTimeString from an ISO-8601 formatted string (string must be a complete and valid timestamp using Karabo agreed ISO-8601 subset API)

timePoint : ISO 8601 formatted string (see formats locale to more information)

Return : DateTimeString object

ptimeToSecondsSinceEpoch

static const unsigned long long ptimeToSecondsSinceEpoch(std::chrono::system_clock::time_point tp)

Convert a specific clock time point to the number of seconds since epoch (1970-Jan-1 00:00:00)

tp : specific (std::chrono::system_clock) time point

Return : number of seconds since epoch