libUTL++
utl::Duration Class Reference

Duration of time. More...

#include <Duration.h>

Inheritance diagram for utl::Duration:

Public Member Functions

 Duration (double seconds)
 Constructor. More...
 
 Duration (const String &str)
 Constructor. More...
 
 Duration (uint_t days, uint_t hours, uint_t minutes, double seconds)
 Constructor. More...
 
virtual String toString () const
 Return a string representation of self. More...
 
uint_t days () const
 Get the number of days. More...
 
uint_t hours () const
 Get the number of hours. More...
 
uint_t minutes () const
 Get the number of minutes. More...
 
double seconds () const
 Get the number of seconds. More...
 
virtual Number< double > & set (const String &str)
 Set with a format string. More...
 
void set (uint_t days, uint_t hours, uint_t minutes, double seconds)
 Set a new duration. More...
 
void setUnit (uint_t unit, uint_t num=1)
 Set to a multiple of a given unit. More...
 
Duration operator+ (const Duration &rhs) const
 Add the given duration to self and return the result. More...
 
Duration operator- (const Duration &rhs) const
 Subtract the given duration from self and return the result. More...
 
- Public Member Functions inherited from utl::Float
 Float (double f)
 Constructor. More...
 
 Float (const String &str)
 Constructor. More...
 
virtual int compare (const Object &rhs) const
 Compare with another object. More...
 
virtual void serialize (Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize to or from a stream. More...
 
String toString (uint_t digits) const
 Get a string representation. More...
 
bool isInt () const
 Determine whether the number is an integer (has no fractional component). More...
 
Float abs () const
 Get the absolute value of self. More...
 
Float mod (const Float &rhs) const
 Get the result of self modulo rhs. More...
 
- Public Member Functions inherited from utl::Number< double >
 Number (double n)
 Constructor. More...
 
String toString (const char *fmt) const
 Convert to string. More...
 
double get () const
 Get the value. More...
 
void set (double n)
 Set the value. More...
 
 operator double () const
 Conversion to built-in type. More...
 
Number< double > & operator+= (double rhs)
 
Number< double > & operator+= (const Number< double > &rhs)
 
Number< double > & operator-= (double rhs)
 
Number< double > & operator-= (const Number< double > &rhs)
 
Number< double > & operator*= (double rhs)
 
Number< double > & operator*= (const Number< double > &rhs)
 
Number< double > & operator/= (double rhs)
 
Number< double > & operator/= (const Number< double > &rhs)
 
double operator+ (double rhs) const
 
double operator+ (const Number< double > &rhs) const
 
double operator- (double rhs) const
 
double operator- (const Number< double > &rhs) const
 
double operator* (double rhs) const
 
Number< double > operator* (const Number< double > &rhs) const
 
double operator/ (double rhs) const
 
Number< double > operator/ (const Number< double > &rhs) const
 
Number< double > & operator++ ()
 
double operator++ (int)
 
Number< double > & operator-- ()
 
double operator-- (int)
 
- Public Member Functions inherited from utl::Object
void clear ()
 Revert to initial state. More...
 
virtual void vclone (const Object &rhs)
 Make an exact copy of another instance. More...
 
virtual void steal (Object &rhs)
 "Steal" the internal representation from another instance. More...
 
virtual void dump (Stream &os, uint_t level=uint_t_max) const
 Dump a human-readable representation of self to the given output stream. More...
 
void dumpWithClassName (Stream &os, uint_t indent=4, uint_t level=uint_t_max) const
 Front-end for dump() that prints the object's class name. More...
 
virtual const ObjectgetKey () const
 Get the key for this object. More...
 
bool hasKey () const
 Determine whether or not the object has a key. More...
 
virtual const ObjectgetProxiedObject () const
 Get the proxied object (= self if none). More...
 
virtual ObjectgetProxiedObject ()
 Get the proxied object (= self if none). More...
 
virtual size_t hash (size_t size) const
 Get the hash code for the object. More...
 
bool _isA (const RunTimeClass *runTimeClass) const
 Determine whether self's class is a descendent of the given class. More...
 
 operator String () const
 Conversion to String. More...
 
size_t allocatedSize () const
 Get the total allocated size of this object. More...
 
virtual size_t innerAllocatedSize () const
 Get the "inner" allocated size. More...
 
virtual void addOwnedIt (const class FwdIt *it) const
 Notify self that it owns the given iterator. More...
 
virtual void removeOwnedIt (const class FwdIt *it) const
 Notify self that the given owned iterator has been destroyed. More...
 
bool operator< (const Object &rhs) const
 Less-than operator. More...
 
bool operator<= (const Object &rhs) const
 Less-than-or-equal-to operator. More...
 
bool operator> (const Object &rhs) const
 Greater-than operator. More...
 
bool operator>= (const Object &rhs) const
 Greater-than-or-equal-to operator. More...
 
bool operator== (const Object &rhs) const
 Equal-to operator. More...
 
bool operator!= (const Object &rhs) const
 Unequal-to operator. More...
 
void serializeIn (Stream &is, uint_t mode=ser_default)
 Serialize from an input stream. More...
 
void serializeOut (Stream &os, uint_t mode=ser_default) const
 Serialize to an output stream. More...
 
void serializeOutBoxed (Stream &os, uint_t mode=ser_default) const
 Serialize a boxed object to an output stream. More...
 

Static Public Member Functions

static Duration days (double numDays)
 Get duration in number of days. More...
 
static Duration hours (double numHours)
 Get duration in number of hours. More...
 
static Duration minutes (double numMinutes)
 Get duration in number of minutes. More...
 
static Duration seconds (uint64_t numSeconds)
 Get duration in number of seconds. More...
 
- Static Public Member Functions inherited from utl::Object
static ObjectserializeInNullable (Stream &is, uint_t mode=ser_default)
 Serialize a nullptr-able object from an input stream. More...
 
static void serializeOutNullable (const Object *object, Stream &os, uint_t mode=ser_default)
 Serialize a nullptr-able object to an output stream. More...
 
static void serializeNullable (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a nullptr-able object to or from a stream. More...
 
static ObjectserializeInBoxed (Stream &is, uint_t mode=ser_default)
 Serialize a boxed object from an input stream. More...
 
static void serializeBoxed (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boxed object to or from a stream. More...
 

Static Public Attributes

static const Duration oneDay
 Duration of one day. More...
 
static const Duration oneHour
 Duration of one hour. More...
 
static const Duration oneHalfHour
 Duration of half an hour. More...
 
static const Duration oneMinute
 Duration of one minute. More...
 
static const Duration oneSecond
 Duration of one second. More...
 

Detailed Description

Duration of time.

String Representation Formatting

The format string takes the form:

[<numDays> d] [<numHours> h] [<numMinutes> m] [<numSeconds> s]

The following are examples of valid format strings:

  • "1d 4m 5s" => one day, 4 minutes, 5 seconds
  • "3h 15s" => three hours, 15 seconds
Author
Adam McKee

Definition at line 40 of file Duration.h.

Constructor & Destructor Documentation

◆ Duration() [1/3]

utl::Duration::Duration ( double  seconds)
inline

Constructor.

Parameters
secondsnumber of seconds

Definition at line 50 of file Duration.h.

◆ Duration() [2/3]

utl::Duration::Duration ( const String str)
inline

Constructor.

Parameters
strformat string

Definition at line 59 of file Duration.h.

◆ Duration() [3/3]

utl::Duration::Duration ( uint_t  days,
uint_t  hours,
uint_t  minutes,
double  seconds 
)
inline

Constructor.

Parameters
daysnumber of days
hoursnumber of hours
minutesnumber of minutes
secondsnumber of seconds

Definition at line 71 of file Duration.h.

References utl::toString().

Member Function Documentation

◆ toString()

virtual String utl::Duration::toString ( ) const
virtual

Return a string representation of self.

Reimplemented from utl::Float.

◆ days() [1/2]

uint_t utl::Duration::days ( ) const
inline

Get the number of days.

Definition at line 80 of file Duration.h.

◆ hours() [1/2]

uint_t utl::Duration::hours ( ) const
inline

Get the number of hours.

Definition at line 87 of file Duration.h.

◆ minutes() [1/2]

uint_t utl::Duration::minutes ( ) const
inline

Get the number of minutes.

Definition at line 96 of file Duration.h.

◆ seconds() [1/2]

double utl::Duration::seconds ( ) const
inline

Get the number of seconds.

Definition at line 105 of file Duration.h.

◆ set() [1/2]

virtual Number<double>& utl::Duration::set ( const String str)
virtual

Set with a format string.

Reimplemented from utl::Float.

◆ set() [2/2]

void utl::Duration::set ( uint_t  days,
uint_t  hours,
uint_t  minutes,
double  seconds 
)

Set a new duration.

Parameters
daysnumber of days
hoursnumber of hours
minutesnumber of minutes
secondsnumber of seconds

◆ setUnit()

void utl::Duration::setUnit ( uint_t  unit,
uint_t  num = 1 
)

Set to a multiple of a given unit.

Parameters
unit(see utl::tm_unit_t)
nummultiple of the given unit

◆ operator+()

Duration utl::Duration::operator+ ( const Duration rhs) const
inline

Add the given duration to self and return the result.

Returns
self plus rhs
Parameters
rhsduration to add

Definition at line 134 of file Duration.h.

◆ operator-()

Duration utl::Duration::operator- ( const Duration rhs) const
inline

Subtract the given duration from self and return the result.

Returns
self minus rhs
Parameters
rhsduration to subtract

Definition at line 144 of file Duration.h.

◆ days() [2/2]

static Duration utl::Duration::days ( double  numDays)
inlinestatic

Get duration in number of days.

Definition at line 151 of file Duration.h.

◆ hours() [2/2]

static Duration utl::Duration::hours ( double  numHours)
inlinestatic

Get duration in number of hours.

Definition at line 158 of file Duration.h.

◆ minutes() [2/2]

static Duration utl::Duration::minutes ( double  numMinutes)
inlinestatic

Get duration in number of minutes.

Definition at line 165 of file Duration.h.

◆ seconds() [2/2]

static Duration utl::Duration::seconds ( uint64_t  numSeconds)
inlinestatic

Get duration in number of seconds.

Definition at line 172 of file Duration.h.

Member Data Documentation

◆ oneDay

const Duration utl::Duration::oneDay
static

Duration of one day.

Definition at line 179 of file Duration.h.

◆ oneHour

const Duration utl::Duration::oneHour
static

Duration of one hour.

Definition at line 181 of file Duration.h.

◆ oneHalfHour

const Duration utl::Duration::oneHalfHour
static

Duration of half an hour.

Definition at line 183 of file Duration.h.

◆ oneMinute

const Duration utl::Duration::oneMinute
static

Duration of one minute.

Definition at line 185 of file Duration.h.

◆ oneSecond

const Duration utl::Duration::oneSecond
static

Duration of one second.

Definition at line 187 of file Duration.h.


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