Classes Files

Wombat::MamaDateTime

More…

#include <MamaDateTime.h>

Public Functions

  Name
  MamaDateTime()
  MamaDateTime(const MamaDateTime & copy)
  MamaDateTime(const char * str, const MamaTimeZone * tz =NULL)
  ~MamaDateTime()
MamaDateTime & operator=(const MamaDateTime & rhs)
bool operator==(const MamaDateTime & rhs) const
bool operator!=(const MamaDateTime & rhs) const
bool operator<(const MamaDateTime & rhs) const
bool operator>(const MamaDateTime & rhs) const
int compare(const MamaDateTime & rhs) const
bool empty() const
void setEpochTime(mama_u32_t secondsSinceEpoch, mama_u32_t microseconds, mamaDateTimePrecision precision =MAMA_DATE_TIME_PREC_UNKNOWN)
void setEpochTimeF64(double secondsSinceEpoch)
void setEpochTimeMilliseconds(mama_u64_t millisecondsSinceEpoch)
void setEpochTimeMicroseconds(mama_u64_t microsecondsSinceEpoch)
void setWithHints(mama_u32_t secondsSinceEpoch, mama_u32_t microseconds, mamaDateTimePrecision precision =MAMA_DATE_TIME_PREC_UNKNOWN, mamaDateTimeHints hints =0)
mamaDateTimePrecision getPrecision()
void setPrecision(mamaDateTimePrecision precision)
mamaDateTimeHints getHints()
void setHints(mamaDateTimeHints hints)
void setFromString(const char * str, const MamaTimeZone * tz =NULL)
void setFromString(const char * str, mama_size_t strLen, const MamaTimeZone * tz =NULL)
void setToNow()
void setToMidnightToday(const MamaTimeZone * tz =NULL)
void setFromStructTimeSpec(struct timespec & inputTimeSpec)
void set(struct timeval inputTimeVal)
void set(mama_u32_t year, mama_u32_t month, mama_u32_t day, mama_u32_t hour, mama_u32_t minute, mama_u32_t second, mama_u32_t microsecond, mamaDateTimePrecision precision =MAMA_DATE_TIME_PREC_UNKNOWN, const MamaTimeZone * tz =NULL)
void setTime(mama_u32_t hour, mama_u32_t minute, mama_u32_t second, mama_u32_t microsecond, mamaDateTimePrecision precision =MAMA_DATE_TIME_PREC_UNKNOWN, const MamaTimeZone * tz =NULL)
void setDate(mama_u32_t year, mama_u32_t month, mama_u32_t day)
void copyTime(const MamaDateTime & copy)
void copyDate(const MamaDateTime & copy)
void clear()
void clearTime()
void clearDate()
void addSeconds(mama_f64_t seconds)
void addSeconds(mama_i32_t seconds)
void addMicroseconds(mama_i64_t microSeconds)
mama_u64_t getEpochTimeMicroseconds() const
mama_u64_t getEpochTimeMicroseconds(const MamaTimeZone & tz) const
mama_u64_t getEpochTimeMilliseconds() const
mama_u64_t getEpochTimeMilliseconds(const MamaTimeZone & tz) const
mama_f64_t getEpochTimeSeconds() const
mama_f64_t getEpochTimeSeconds(const MamaTimeZone & tz) const
mama_i64_t getEpochTimeExtSeconds() const
uint32_t getEpochTimeExtNanoseconds() const
void setEpochTimeExt(mama_i64_t seconds, uint32_t nanoseconds) const
mama_f64_t getEpochTimeSecondsWithCheck() const
void getAsString(char * result, mama_size_t maxLen) const
void getTimeAsString(char * result, mama_size_t maxLen) const
void getDateAsString(char * result, mama_size_t maxLen) const
const char * getAsString() const
const char * getTimeAsString() const
const char * getDateAsString() const
void getAsFormattedString(char * result, mama_size_t maxLen, const char * format) const
void getAsFormattedString(char * result, mama_size_t maxLen, const char * format, const MamaTimeZone & tz) const
void getAsStructTimeVal(struct timeval & result) const
void getAsStructTimeVal(struct timeval & result, const MamaTimeZone & tz) const
void getAsStructTimeSpec(struct timespec & result) const
void getAsStructTm(struct tm & result) const
void getAsStructTm(struct tm & result, const MamaTimeZone & tz) const
mama_u32_t getYear() const
mama_u32_t getMonth() const
mama_u32_t getDay() const
mama_u32_t getHour() const
mama_u32_t getMinute() const
mama_u32_t getSecond() const
mama_u32_t getMicrosecond() const
mamaDayOfWeek getDayOfWeek() const
bool hasTime() const
bool hasDate() const
mamaDateTime getCValue()
const mamaDateTime getCValue() const

Detailed Description

class Wombat::MamaDateTime;

A date/time representation with additional hints for precision, advanced output formatting and support for time zone conversion (using the MamaTimeZone type).

Hints include:

  • Whether the time stamp contains a date part, a time part, or both.
  • The level of accuracy (if known) of the time part (e.g., minutes, seconds, milliseconds, etc.). The output format strings are similar to that available for the strftime() function with the addition of %; which adds optional (non-zero) fractional second to the string, and %: which adds fractional seconds including trailing zeros, but does not include the “.”. The following table provides examples of output.
Actual Time Output of “%T%;” Output of “%T%.:”
     
01:23:45 and 678 millisecs 01:23:45.678 01:23:45.678
01:23:45 and 0 millisecs 01:23:45 01:23:45.000

Public Functions Documentation

function MamaDateTime

MamaDateTime()

function MamaDateTime

MamaDateTime(
    const MamaDateTime & copy
)

function MamaDateTime

explicit MamaDateTime(
    const char * str,
    const MamaTimeZone * tz =NULL
)

Constructor taking a string argument. This is the same as calling setFromString() immediately after construction.

function ~MamaDateTime

~MamaDateTime()

function operator=

MamaDateTime & operator=(
    const MamaDateTime & rhs
)

function operator==

bool operator==(
    const MamaDateTime & rhs
) const

function operator!=

inline bool operator!=(
    const MamaDateTime & rhs
) const

function operator<

bool operator<(
    const MamaDateTime & rhs
) const

function operator>

bool operator>(
    const MamaDateTime & rhs
) const

function compare

int compare(
    const MamaDateTime & rhs
) const

function empty

bool empty() const

function setEpochTime

void setEpochTime(
    mama_u32_t secondsSinceEpoch,
    mama_u32_t microseconds,
    mamaDateTimePrecision precision =MAMA_DATE_TIME_PREC_UNKNOWN
)

function setEpochTimeF64

void setEpochTimeF64(
    double secondsSinceEpoch
)

function setEpochTimeMilliseconds

void setEpochTimeMilliseconds(
    mama_u64_t millisecondsSinceEpoch
)

function setEpochTimeMicroseconds

void setEpochTimeMicroseconds(
    mama_u64_t microsecondsSinceEpoch
)

function setWithHints

void setWithHints(
    mama_u32_t secondsSinceEpoch,
    mama_u32_t microseconds,
    mamaDateTimePrecision precision =MAMA_DATE_TIME_PREC_UNKNOWN,
    mamaDateTimeHints hints =0
)

function getPrecision

mamaDateTimePrecision getPrecision()

function setPrecision

void setPrecision(
    mamaDateTimePrecision precision
)

function getHints

mamaDateTimeHints getHints()

function setHints

void setHints(
    mamaDateTimeHints hints
)

function setFromString

void setFromString(
    const char * str,
    const MamaTimeZone * tz =NULL
)

function setFromString

void setFromString(
    const char * str,
    mama_size_t strLen,
    const MamaTimeZone * tz =NULL
)

function setToNow

void setToNow()

function setToMidnightToday

void setToMidnightToday(
    const MamaTimeZone * tz =NULL
)

function setFromStructTimeSpec

void setFromStructTimeSpec(
    struct timespec & inputTimeSpec
)

Set the underlying C mamaDateTime from a TimeSpec Struct. This will allow for extended date ranges.

function set

void set(
    struct timeval inputTimeVal
)

Set the underlying C mamaDateTime from a TimeVal Struct. This will allow for extended date ranges.

function set

void set(
    mama_u32_t year,
    mama_u32_t month,
    mama_u32_t day,
    mama_u32_t hour,
    mama_u32_t minute,
    mama_u32_t second,
    mama_u32_t microsecond,
    mamaDateTimePrecision precision =MAMA_DATE_TIME_PREC_UNKNOWN,
    const MamaTimeZone * tz =NULL
)

Parameters:

  • year The year (must be 1970 or later).
  • month The month (1 - 12).
  • day The day (1 - 31).
  • hour The hour (0 - 23).
  • minute The minute (0 - 59).
  • second The second (0 - 59).
  • microsecond The second (0 - 999999).
  • precision An explicit precision, if known.
  • tz A timezone to shift from.

Set the entire date and time for the MamaDateTime. The year, month and day parameters must all be integers greater than zero.

function setTime

void setTime(
    mama_u32_t hour,
    mama_u32_t minute,
    mama_u32_t second,
    mama_u32_t microsecond,
    mamaDateTimePrecision precision =MAMA_DATE_TIME_PREC_UNKNOWN,
    const MamaTimeZone * tz =NULL
)

Parameters:

  • hour The hour (0 - 23).
  • minute The minute (0 - 59).
  • second The second (0 - 59).
  • microsecond The second (0 - 999999).
  • precision An explicit precision, if known.
  • tz A timezone to shift from.

Set the time-of-day portion of the MamaDateTime. The date portion is not affected.

function setDate

void setDate(
    mama_u32_t year,
    mama_u32_t month,
    mama_u32_t day
)

Parameters:

  • year The year (must be 1970 or later).
  • month The month (1 - 12).
  • day The day (1 - 31).

Set the date portion of the MamaDateTime. The time-of-day portion is not affected. The year, month and day parameters must all be integers greater than zero.

function copyTime

void copyTime(
    const MamaDateTime & copy
)

Parameters:

  • copy The object to copy from

Copy the time-of-day portion of the MamaDateTime. The date portion is not affected.

function copyDate

void copyDate(
    const MamaDateTime & copy
)

Parameters:

  • copy The object to copy from

Copy the date portion of the MamaDateTime. The time-of-day portion is not affected.

function clear

void clear()

Clear the entire MamaDateTime.

function clearTime

void clearTime()

Clear the time-of-day portion of the MamaDateTime. The date portion is not affected.

function clearDate

void clearDate()

Clear the date portion of the MamaDateTime. The time-of-day portion is not affected.

function addSeconds

void addSeconds(
    mama_f64_t seconds
)

function addSeconds

void addSeconds(
    mama_i32_t seconds
)

function addMicroseconds

void addMicroseconds(
    mama_i64_t microSeconds
)

function getEpochTimeMicroseconds

mama_u64_t getEpochTimeMicroseconds() const

Return: The number of microseconds since the Epoch.

Get the date and time as microseconds since the Epoch, (using the UTC timezone).

function getEpochTimeMicroseconds

mama_u64_t getEpochTimeMicroseconds(
    const MamaTimeZone & tz
) const

Parameters:

  • [int] tz The timezone.

Return: The number of microseconds since the Epoch.

Get the date and time as microseconds since the Epoch in the supplied time zone.

function getEpochTimeMilliseconds

mama_u64_t getEpochTimeMilliseconds() const

function getEpochTimeMilliseconds

mama_u64_t getEpochTimeMilliseconds(
    const MamaTimeZone & tz
) const

function getEpochTimeSeconds

mama_f64_t getEpochTimeSeconds() const

function getEpochTimeSeconds

mama_f64_t getEpochTimeSeconds(
    const MamaTimeZone & tz
) const

function getEpochTimeExtSeconds

mama_i64_t getEpochTimeExtSeconds() const

Return: The number of whole seconds since the Epoch.

Get the extended datetime value in whole seconds since the Epoch (UTC).

function getEpochTimeExtNanoseconds

uint32_t getEpochTimeExtNanoseconds() const

Return: The nanosecond portion of the datetime value.

Get the extended datetime subsecond portion of the datetime value in nanoseconds.

function setEpochTimeExt

void setEpochTimeExt(
    mama_i64_t seconds,
    uint32_t nanoseconds
) const

Parameters:

  • seconds The number of seconds since the Epoch.
  • nanoseconds The number of nanoseconds since the seconds parameter.

Set the extended datetime values expressed in seconds since the Epoch (UTC) and nanoseconds since this epoch time.

function getEpochTimeSecondsWithCheck

mama_f64_t getEpochTimeSecondsWithCheck() const

Return: The number of seconds, (including partial seconds), since the Epoch.

Get the date and time as seconds since the Epoch, (using the UTC timezone). If no date value is contained in the dateTime then it will be set to today’s date and the calculation made.

function getAsString

void getAsString(
    char * result,
    mama_size_t maxLen
) const

function getTimeAsString

void getTimeAsString(
    char * result,
    mama_size_t maxLen
) const

function getDateAsString

void getDateAsString(
    char * result,
    mama_size_t maxLen
) const

function getAsString

const char * getAsString() const

Return a string representation of the date/time. Note that the alternative getAsString() methods are more efficient because these method must allocate a temporary buffer (automatically destroyed upon object destruction). The timezone must to set to UTC if calling this from multiple threads concurrently to avoid contention in strftime.p

function getTimeAsString

const char * getTimeAsString() const

function getDateAsString

const char * getDateAsString() const

function getAsFormattedString

void getAsFormattedString(
    char * result,
    mama_size_t maxLen,
    const char * format
) const

function getAsFormattedString

void getAsFormattedString(
    char * result,
    mama_size_t maxLen,
    const char * format,
    const MamaTimeZone & tz
) const

function getAsStructTimeVal

void getAsStructTimeVal(
    struct timeval & result
) const

function getAsStructTimeVal

void getAsStructTimeVal(
    struct timeval & result,
    const MamaTimeZone & tz
) const

function getAsStructTimeSpec

void getAsStructTimeSpec(
    struct timespec & result
) const

function getAsStructTm

void getAsStructTm(
    struct tm & result
) const

function getAsStructTm

void getAsStructTm(
    struct tm & result,
    const MamaTimeZone & tz
) const

function getYear

mama_u32_t getYear() const

function getMonth

mama_u32_t getMonth() const

function getDay

mama_u32_t getDay() const

function getHour

mama_u32_t getHour() const

function getMinute

mama_u32_t getMinute() const

function getSecond

mama_u32_t getSecond() const

function getMicrosecond

mama_u32_t getMicrosecond() const

function getDayOfWeek

mamaDayOfWeek getDayOfWeek() const

function hasTime

bool hasTime() const

Return whether the object has a time component.

function hasDate

bool hasDate() const

Return whether the object has a date component.

function getCValue

mamaDateTime getCValue()

function getCValue

const mamaDateTime getCValue() const

Updated on 2023-03-31 at 15:29:25 +0100