Time expressed in hours, minutes, seconds and milliseconds More...

#include <tntdb/cxxtools/time.h>

Public Member Functions

 Time ()
 Creates a Time set to zero.
 Time (const std::string &d, const std::string &fmt="%H:%M:%S%j")
 create Time from string using format
 Time (unsigned h, unsigned m, unsigned s=0, unsigned ms=0, unsigned usec=0)
 Creates a Time from given values.
unsigned hour () const
 Returns the hour-part of the Time.
unsigned minute () const
 Returns the minute-part of the Time.
unsigned second () const
 Returns the second-part of the Time.
unsigned msec () const
 Returns the millisecond-part of the Time.
unsigned usec () const
 Returns the microseconds of the Time.
unsigned totalMSecs () const
uint64_t totalUSecs () const
void setTotalMSecs (unsigned msecs)
void setTotalUSecs (uint64_t m)
void set (unsigned hour, unsigned min, unsigned sec, unsigned msec=0, unsigned usec=0)
 Sets the time.
void get (unsigned &h, unsigned &m, unsigned &s, unsigned &ms) const
 Get the time values.
void get (unsigned &h, unsigned &m, unsigned &s, unsigned &ms, unsigned &us) const
 Get the time values.
std::string toString (const std::string &fmt="%H:%M:%S%j") const
 format Time into a string using a format string
Timeoperator= (const Time &other)
 Assignment operator.
bool operator== (const Time &other) const
 Equal comparison operator.
bool operator!= (const Time &other) const
 Inequal comparison operator.
bool operator< (const Time &other) const
 Less-than comparison operator.
bool operator<= (const Time &other) const
 Less-than-or-equal comparison operator.
bool operator> (const Time &other) const
 Greater-than comparison operator.
bool operator>= (const Time &other) const
 Greater-than-or-equal comparison operator.
Timeoperator+= (const Timespan &ts)
 Assignment by sum operator.
Timeoperator-= (const Timespan &ts)
 Assignment by difference operator.
std::string toIsoString () const
 Returns the time in ISO-format (hh:mm:ss.hhh)

Static Public Member Functions

static bool isValid (unsigned h, unsigned m, unsigned s, unsigned ms)
 Returns true if values are a valid time.
static bool isValid (unsigned h, unsigned m, unsigned s, unsigned ms, unsigned usec)
 Returns true if values are a valid time.
static Time fromIsoString (const std::string &s)
 Convert from an ISO time string.

Static Public Attributes

static const unsigned MaxHours = 23
static const unsigned HoursPerDay = 24
static const unsigned MaxMinutes = 59
static const unsigned MinutesPerHour = 60
static const unsigned MinutesPerDay = 1440
static const unsigned MaxSeconds = 59
static const unsigned SecondsPerDay = 86400
static const unsigned SecondsPerHour = 3600
static const unsigned SecondsPerMinute = 60
static const unsigned MSecsPerDay = 86400000
static const unsigned MSecsPerHour = 3600000
static const unsigned MSecsPerMinute = 60000
static const unsigned MSecsPerSecond = 1000
static const uint64_t USecsPerDay = static_cast<uint64_t>(MSecsPerDay) * 1000

Friends

Time operator+ (const Time &time, const Timespan &ts)
 Addition operator.
Time operator- (const Time &time, const Timespan &ts)
 Subtraction operator.
Timespan operator- (const Time &a, const Time &b)
 Subtraction operator.

Detailed Description

Time expressed in hours, minutes, seconds and milliseconds

Constructor & Destructor Documentation

cxxtools::Time::Time ( )
inline

Creates a Time set to zero.

cxxtools::Time::Time ( const std::string &  d,
const std::string &  fmt = "%H:%M:%S%j" 
)
explicit

create Time from string using format

Valid format codes are:

H hours (0-23) I hours (0-11) %2I hours (00-11) M minutes (0-59) %2M minutes (00-59) S seconds (0-59) %2S seconds (00-59) j fractional seconds (1-6 digits, optionally leading '.') J fractional seconds (1-6 digits, with leading '.') K milliseconds (3 digits, with leading '.') k milliseconds (3 digits) U microseconds (6 digits, with leading '.') u microseconds (6 digits) p AM/PM ? arbitrary character skip non digit characters

cxxtools::Time::Time ( unsigned  h,
unsigned  m,
unsigned  s = 0,
unsigned  ms = 0,
unsigned  usec = 0 
)
inline

Creates a Time from given values.

InvalidTime is thrown if one or more of the values are out of range

Member Function Documentation

static Time cxxtools::Time::fromIsoString ( const std::string &  s)
inlinestatic

Convert from an ISO time string.

Interprets the passed string as a time-string in ISO-format (hh:mm:ss.hhh) and returns a Time-object. If the string is not in ISO-format, InvalidTime is thrown.

void cxxtools::Time::get ( unsigned &  h,
unsigned &  m,
unsigned &  s,
unsigned &  ms 
) const
inline

Get the time values.

Gets the hour, minute, second and millisecond parts of the time.

void cxxtools::Time::get ( unsigned &  h,
unsigned &  m,
unsigned &  s,
unsigned &  ms,
unsigned &  us 
) const
inline

Get the time values.

Gets the hour, minute, second, millisecond and microsecond parts of the time. Note that the microseconds include the millisecons.

unsigned cxxtools::Time::hour ( ) const
inline

Returns the hour-part of the Time.

static bool cxxtools::Time::isValid ( unsigned  h,
unsigned  m,
unsigned  s,
unsigned  ms 
)
inlinestatic

Returns true if values are a valid time.

static bool cxxtools::Time::isValid ( unsigned  h,
unsigned  m,
unsigned  s,
unsigned  ms,
unsigned  usec 
)
inlinestatic

Returns true if values are a valid time.

unsigned cxxtools::Time::minute ( ) const
inline

Returns the minute-part of the Time.

unsigned cxxtools::Time::msec ( ) const
inline

Returns the millisecond-part of the Time.

bool cxxtools::Time::operator!= ( const Time other) const
inline

Inequal comparison operator.

Time& cxxtools::Time::operator+= ( const Timespan ts)

Assignment by sum operator.

Time& cxxtools::Time::operator-= ( const Timespan ts)

Assignment by difference operator.

bool cxxtools::Time::operator< ( const Time other) const
inline

Less-than comparison operator.

bool cxxtools::Time::operator<= ( const Time other) const
inline

Less-than-or-equal comparison operator.

Time& cxxtools::Time::operator= ( const Time other)
inline

Assignment operator.

bool cxxtools::Time::operator== ( const Time other) const
inline

Equal comparison operator.

bool cxxtools::Time::operator> ( const Time other) const
inline

Greater-than comparison operator.

bool cxxtools::Time::operator>= ( const Time other) const
inline

Greater-than-or-equal comparison operator.

unsigned cxxtools::Time::second ( ) const
inline

Returns the second-part of the Time.

void cxxtools::Time::set ( unsigned  hour,
unsigned  min,
unsigned  sec,
unsigned  msec = 0,
unsigned  usec = 0 
)
inline

Sets the time.

Sets the time to a new hour, minute, second, milli-second. InvalidTime is thrown if one or more of the values are out of range

void cxxtools::Time::setTotalMSecs ( unsigned  msecs)
inline
void cxxtools::Time::setTotalUSecs ( uint64_t  m)
inline
std::string cxxtools::Time::toIsoString ( ) const
inline

Returns the time in ISO-format (hh:mm:ss.hhh)

std::string cxxtools::Time::toString ( const std::string &  fmt = "%H:%M:%S%j") const

format Time into a string using a format string

Valid format codes are:

%1H hours (0-23) I hours (00-11) %1I hours (0-11) M minutes (00-59) %1M minutes (0-59) S seconds (00-59) %1S seconds (0-59) j fractional seconds (1-6 digits, optionally leading '.') J fractional seconds (1-6 digits, with leading '.') K milliseconds (3 digits, with leading '.') k milliseconds (3 digits) U microseconds (6 digits, with leading '.') u microseconds (6 digits) p am/pm P AM/PM

unsigned cxxtools::Time::totalMSecs ( ) const
inline
uint64_t cxxtools::Time::totalUSecs ( ) const
inline
unsigned cxxtools::Time::usec ( ) const
inline

Returns the microseconds of the Time.

Note that the microsoecnds contain the milliseconds also.

Friends And Related Function Documentation

Time operator+ ( const Time time,
const Timespan ts 
)
friend

Addition operator.

Time operator- ( const Time time,
const Timespan ts 
)
friend

Subtraction operator.

Timespan operator- ( const Time a,
const Time b 
)
friend

Subtraction operator.

Member Data Documentation

const unsigned cxxtools::Time::HoursPerDay = 24
static
const unsigned cxxtools::Time::MaxHours = 23
static
const unsigned cxxtools::Time::MaxMinutes = 59
static
const unsigned cxxtools::Time::MaxSeconds = 59
static
const unsigned cxxtools::Time::MinutesPerDay = 1440
static
const unsigned cxxtools::Time::MinutesPerHour = 60
static
const unsigned cxxtools::Time::MSecsPerDay = 86400000
static
const unsigned cxxtools::Time::MSecsPerHour = 3600000
static
const unsigned cxxtools::Time::MSecsPerMinute = 60000
static
const unsigned cxxtools::Time::MSecsPerSecond = 1000
static
const unsigned cxxtools::Time::SecondsPerDay = 86400
static
const unsigned cxxtools::Time::SecondsPerHour = 3600
static
const unsigned cxxtools::Time::SecondsPerMinute = 60
static
const uint64_t cxxtools::Time::USecsPerDay = static_cast<uint64_t>(MSecsPerDay) * 1000
static

The documentation for this class was generated from the following file:
  • include/tntdb/cxxtools/time.h