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

#include <cxxtools/time.h>

Public Member Functions

 Time ()
 Creates a Time set to zero.
 Time (unsigned h, unsigned m, unsigned s=0, unsigned ms=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 totalMSecs () const
void setTotalMSecs (unsigned msecs)
void set (unsigned hour, unsigned min, unsigned sec, unsigned msec=0)
 Sets the time.
void get (unsigned &h, unsigned &m, unsigned &s, unsigned &ms) const
 Get the time values.
Time addSecs (int secs) const
 Adds seconds to the time.
int secsTo (const Time &t) const
 Determines seconds until another time.
Time addMSecs (int64_t ms) const
 Adds milliseconds to the time.
int64_t msecsTo (const Time &t) const
 Determines milliseconds until another time.
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 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

Friends

Time operator+ (const Time &time, const Timespan &ts)
 Addition operator.
Time operator- (const Time &time, const Timespan &ts)
 Substraction operator.
Timespan operator- (const Time &a, const Time &b)
 Substraction 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 ( unsigned  h,
unsigned  m,
unsigned  s = 0,
unsigned  ms = 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

Time cxxtools::Time::addMSecs ( int64_t  ms) const
inline

Adds milliseconds to the time.

This method does not change the time, but returns the time with the milliseconds added.

Time cxxtools::Time::addSecs ( int  secs) const
inline

Adds seconds to the time.

This method does not change the time, but returns the time with the seconds added.

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.

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.

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.

int64_t cxxtools::Time::msecsTo ( const Time t) const
inline

Determines milliseconds until another time.

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

Inequal comparison operator.

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

Assignment by sum operator.

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

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.

int cxxtools::Time::secsTo ( const Time t) const
inline

Determines seconds until another time.

void cxxtools::Time::set ( unsigned  hour,
unsigned  min,
unsigned  sec,
unsigned  msec = 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
std::string cxxtools::Time::toIsoString ( ) const
inline

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

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

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

Substraction operator.

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

Substraction 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

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