LRAUV  revA
Timespan Class Reference

Timespan class, represents a delta of time. More...

#include <Timestamp.h>

Inheritance diagram for Timespan:
Collaboration diagram for Timespan:

Public Member Functions

 Timespan (const double &seconds)
 Constructor, set time from double. More...
 
 Timespan (const struct timeval &timeval)
 Constructor, set time from struct timeval. More...
 
 Timespan (const Timespan &copyMe=ZERO_TIMESPAN)
 Copy constructor. More...
 
 ~Timespan ()
 Destructor. More...
 
virtual double asDouble () const
 Accessor, convert to double. More...
 
virtual double asFloat () const
 Accessor, convert to float. More...
 
bool setDuration (const char *duration)
 Sets the timespan using an XML-like duration string. More...
 
Timespanoperator+= (const Timespan &rhs)
 Addition with a Timespan. More...
 
Timespanoperator-= (const Timespan &rhs)
 Subtraction of a Timespan. More...
 
Timespanoperator-= (const struct timeval &rhs)
 Subtraction of a Timeval. More...
 
void sleepFor (void) const
 Sleep for the timespan. More...
 
const char * toString (char *buf, int buflen, int precision=3) const
 Writes the Timespan to a unsigned char buffer. More...
 
const Str toString (int precision=3) const
 Writes the Timespan as a Str. More...
 
- Public Member Functions inherited from Timestamp
 Timestamp (const double &seconds)
 Constructor, set time from double. More...
 
 Timestamp (const int seconds, const unsigned int microseconds)
 Constructor, set time from separate seconds and microseconds. More...
 
 Timestamp (const int year, const int month, const int day, const int hour, const int minute, const int second)
 Constructor, set time from separate date and time integers. More...
 
 Timestamp (const struct timeval &timeval)
 Constructor, set time from struct timeval. More...
 
 Timestamp (const char *timeString)
 Constructor, set time from simple y,m,d, h,m,s type formats including ISO9601. More...
 
 Timestamp (const Timestamp &copyMe=NOT_SET_TIME)
 Copy constructor. More...
 
void addFromMicros (const long long &micros)
 add seconds << 20 + microseconds More...
 
void addFromMillis (const long long &millis)
 add seconds << 10 + microseconds >> 10 More...
 
void round (int seconds)
 
virtual ~Timestamp ()
 Destructor. More...
 
Timespan elapsed () const
 Returns the time elapsed since this timestamp. More...
 
long long asMicros () const
 Quickly returns the (seconds << 20) + microseconds (52 bits) More...
 
long long asMillis () const
 Quickly returns the (seconds << 10) + (microseconds >> 10) (42 bits) More...
 
time_t asTimeT () const
 
*struct tm asStructTm () const
 
Timestampoperator= (const Timestamp &rhs)
 Copy operator. More...
 
Timestampoperator= (const double &seconds)
 Set from double. More...
 
Timestampoperator= (const struct timeval &timeval)
 Set from struct timeval. More...
 
Timestampoperator+= (const Timespan &rhs)
 Addition with a Timespan. More...
 
Timestampoperator-= (const Timespan &rhs)
 Subtraction of a Timespan. More...
 
Timestamp operator+ (const Timespan &rhs) const
 Addition to Timespan. More...
 
Timestamp operator- (const Timespan &rhs) const
 Subtraction from Timespan. More...
 
Timespan operator- (const struct timeval &rhs) const
 Subtraction from struct timeval. More...
 
Timespan operator- (const Timestamp &rhs) const
 Subtraction of two times yields a timespan. More...
 
bool operator== (const Timestamp &rhs) const
 Equalities/inequalities. More...
 
bool operator!= (const Timestamp &rhs) const
 Equalities/inequalities. More...
 
bool operator> (const Timestamp &rhs) const
 Greater-than operator. More...
 
bool operator< (const Timestamp &rhs) const
 Less-than operator. More...
 
bool operator<= (const Timestamp &rhs) const
 Greater-than-equal operator. More...
 
bool operator>= (const Timestamp &rhs) const
 Less-than-equal operator. More...
 
TimestampsetToCurrentTime ()
 Set to the current time. More...
 
TimestampsetToMonoTime ()
 Set to clock that represents monotonic time since some unspecified starting point. More...
 
void sleepTill ()
 Sleep until the given time. More...
 
void toTimespec (struct timespec *) const
 Internal conversion function. More...
 
void fromTimespec (const struct timespec *in)
 Internal conversion function. More...
 
const struct timeval & getTimeval () const
 Get the internal storage. More...
 
const char * toString (char *buf, int buflen, int precision=3) const
 Writes the Timestamp as to a unsigned char buffer. More...
 
const Str toString (int precision=3) const
 Writes the Timestamp as a Str. More...
 
const Str toSmallString () const
 Writes the Timestamp as a small Str (YYYYmmdd'T'HHMMSS). More...
 
const Str toSmallerString () const
 Writes the Timestamp as a smaller Str (YYYYmmddHHMM). More...
 
const Str toDateHourString () const
 Writes the Timestamp as a date-hour Str (YYYYmmddHH). More...
 

Static Public Member Functions

static Timespan FromMicros (const long long &micros)
 Named Constructor, set from seconds << 20 + microseconds,. More...
 
static Timespan FromMillis (const long long &millis)
 Named Constructor, set from seconds << 10 + milliseconds >> 10. More...
 
static Timespan Milliseconds (float msec)
 Static allows creation of Timespans denominated in milliseconds. More...
 
static Timespan Seconds (double sec)
 Static allows creation of Timespans denominated in seconds (as a float) This function originally took an integer, but I think this syntax also makes sense. More...
 
static Timespan Minutes (int min)
 Static allows creation of Timespans denominated in minutes. More...
 
static Timespan Hours (int hour)
 Static allows creation of Timespans denominated in hours. More...
 
static Timespan Days (int day)
 Static allows creation of Timespans denominated in days. More...
 
- Static Public Member Functions inherited from Timestamp
static Timestamp FromMicros (const long long &micros)
 Named Constructor, set from seconds << 20 + microseconds,. More...
 
static Timestamp FromMillis (const long long &millis)
 Named Constructor, set from seconds << 10 + milliseconds >> 10. More...
 
static Timestamp Now ()
 Static for current time for use on RHS. More...
 

Static Public Attributes

static const Timespan INVALID_TIMESPAN
 Constant value to represent an invalid timespan. More...
 
static const Timespan ZERO_TIMESPAN
 Constant value to represent instant of time. More...
 
- Static Public Attributes inherited from Timestamp
static const Timestamp NOT_SET_TIME
 Constant value to represent "no time". More...
 
static const Timestamp EPOCH_START_TIME
 Constant value to represent beginning of (1970 Jan 1) epoch. More...
 

Additional Inherited Members

- Public Attributes inherited from Timestamp
*int tm_min
 Returns value as struct tm: int tm_sec; /* seconds. More...
 
*int tm_hour
 
*int tm_mday
 
*int tm_mon
 
*int tm_year
 
*int tm_wday
 
*int tm_yday
 
*int tm_isdst
 
- Protected Member Functions inherited from Timestamp
struct timeval & fromDouble (const double &seconds)
 Set the internal storage to the specified value. More...
 
struct timeval & fromIntegers (const int seconds, const unsigned int microseconds)
 Set the internal storage to the specified values. More...
 
struct timeval & fromIntegers (const int year, const int month, const int day, const int hour, const int minute, const int second)
 Set the internal storage to the specified values. More...
 
struct timeval & fromString (const char *timeString)
 Set the internal storage to the specified ISO9601 string value. More...
 
- Static Protected Member Functions inherited from Timestamp
static struct timeval TimevalFromIntegers (const int seconds, const unsigned int microseconds)
 Returns a struct timeval from the specified values. More...
 
static struct timeval TimevalFromMicros (const long long &micros)
 Returns a struct timeval from asMicros() result. More...
 
static struct timeval TimevalFromMillis (const long long &millis)
 Returns a struct timeval from asMillis() result. More...
 
- Protected Attributes inherited from Timestamp
struct timeval timeval_
 Internal storage for time. More...
 

Detailed Description

Timespan class, represents a delta of time.

Constructor & Destructor Documentation

Timespan::Timespan ( const double &  seconds)

Constructor, set time from double.

Tests:

  1. Create a new object w/o params.

    Expect asDouble() == 0

  2. Create a new object with double param, Expect asDouble() == param

Referenced by Days(), FromMicros(), FromMillis(), Hours(), Milliseconds(), Minutes(), and Seconds().

Timespan::Timespan ( const struct timeval &  timeval)

Constructor, set time from struct timeval.

Timespan::Timespan ( const Timespan rhs = ZERO_TIMESPAN)

Copy constructor.

Tests:

  1. Create new object copied from another object.

    asDouble == asDouble

  2. Create new object copied from another object. Equal with == operator
Timespan::~Timespan ( )
inline

Destructor.

Member Function Documentation

static Timespan Timespan::Days ( int  day)
inlinestatic

Static allows creation of Timespans denominated in days.

References Timespan().

Timespan Timespan::FromMicros ( const long long &  micros)
static

Named Constructor, set from seconds << 20 + microseconds,.

Named Constructor, set from seconds << 20 + microseconds.

References Timespan(), and Timestamp::TimevalFromMicros().

Timespan Timespan::FromMillis ( const long long &  millis)
static

Named Constructor, set from seconds << 10 + milliseconds >> 10.

References Timespan(), and Timestamp::TimevalFromMillis().

static Timespan Timespan::Hours ( int  hour)
inlinestatic
static Timespan Timespan::Minutes ( int  min)
inlinestatic

Static allows creation of Timespans denominated in minutes.

References Timespan().

Referenced by AcousticModem_Benthos_ATM900::parseDebugRxMessage(), AcousticModem_Benthos_ATM900::parseDebugTxMessage(), and Timestamp_Test::testWholeUnits().

Timespan & Timespan::operator+= ( const Timespan rhs)

Addition with a Timespan.

Addition of a Timespan.

Tests:

  1. Create to time objects params A and Timespan B. Sum objects A+=B. Verify (A+B).asDouble() == (A.asDouble + B.asDouble )

References Timestamp::timeval_.

Timespan & Timespan::operator-= ( const Timespan rhs)

Subtraction of a Timespan.

Tests:

  1. Create to time objects params A and Timespan B. Sum objects A-=B. Verify (A-B).asDouble() == (A.asDouble - B.asDouble )

References Timestamp::timeval_.

Timespan & Timespan::operator-= ( const struct timeval &  rhs)

Subtraction of a Timeval.

Subtraction of a struct timeval.

References Timestamp::timeval_.

static Timespan Timespan::Seconds ( double  sec)
inlinestatic

Static allows creation of Timespans denominated in seconds (as a float) This function originally took an integer, but I think this syntax also makes sense.

When called with an integer parameter, it does rely on the implicit conversion from ints to doubles

References Timespan().

Referenced by Batt_Ocean_Server::initialize(), ExternalSim::initialize(), AcousticModem_Benthos_ATM900::parseDebugRxMessage(), AcousticModem_Benthos_ATM900::parseDebugTxMessage(), SettingReader::read(), DataReader::read(), VerticalControl::readConfig(), SCPI::readConfig(), NAL9602::readConfig(), Supervisor::run(), MultiHandler::shutdown(), and Timestamp_Test::testWholeUnits().

bool Timespan::setDuration ( const char *  durationCstr)

Sets the timespan using an XML-like duration string.

format is "P(\d+D)?(\d+H)?(\d+M)?(\d+(.\d+)?S)?" returns true if parsed correctly, false otherwise

Referenced by MissionItem::initializeFromScript().

const char * Timespan::toString ( char *  buf,
int  buflen,
int  precision = 3 
) const

Writes the Timespan to a unsigned char buffer.

Parameters
bufBuffer to write to
buflenMaximum number of characters to write the buffer
precisionNumber of decimals to include in seconds result (up to 6).
Returns
Pointer to buf

References MAX, MIN, and Timestamp::timeval_.

Referenced by ESPClient::consumeResult(), ESPClient::handleException(), ESPComponent::starting(), Timespan_Test::testToString(), toString(), and ESPComponent::waitForESPConnection().

const Str Timespan::toString ( int  precision = 3) const

Writes the Timespan as a Str.

References toString().

Member Data Documentation


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