UCommon
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
ucommon::Time Class Reference

The Time class uses a integer representation of the current time. More...

#include <datetime.h>

Inheritance diagram for ucommon::Time:
Inheritance graph
[legend]

Public Member Functions

long get (void) const
 Get current time in seconds from midnight. More...
 
int hour (void) const
 Get hours from midnight. More...
 
bool is_valid (void) const
 Check if time object had valid value. More...
 
int minute (void) const
 Get minutes from current hour. More...
 
long operator * () const
 Get object time in seconds. More...
 
 operator bool () const
 Check if time object has valid value for is() operator. More...
 
 operator long () const
 Get time in seconds. More...
 
bool operator! () const
 Check if time object has valid value for ! operator. More...
 
bool operator!= (const Time &time) const
 Compare time with another time to see if not same time. More...
 
stringref_t operator() () const
 Convert to standard 24 hour time string. More...
 
const Time operator+ (long seconds) const
 Add seconds to the current time, wrap if 24 hours. More...
 
Timeoperator++ ()
 Incrememnt time by 1 second, wrap on 24 hour period. More...
 
Timeoperator+= (long seconds)
 Increment time by specified seconds. More...
 
long operator- (const Time &reference)
 Get difference (in seconds) between two times. More...
 
const Time operator- (long seconds) const
 Subtract seconds to the current time, wrap if 24 hours. More...
 
Timeoperator-- ()
 Decrement time by 1 second, wrap on 24 hour period. More...
 
Timeoperator-= (long seconds)
 Decrement time by specified seconds. More...
 
bool operator< (const Time &time) const
 Compare time if earlier than another time. More...
 
bool operator<= (const Time &time) const
 Compare time if earlier than or equal to another time. More...
 
Timeoperator= (const Time &time)
 Assign a time as a copy of another time. More...
 
bool operator== (const Time &time) const
 Compare time with another time to see if same time. More...
 
bool operator> (const Time &time) const
 Compare time if later than another time. More...
 
bool operator>= (const Time &time) const
 Compare time if later than or equal to another time. More...
 
const char * put (char *buffer) const
 Get a hh:mm:ss formatted string for current time. More...
 
int second (void) const
 Get seconds from current minute. More...
 
void set (int hour, int minute=0, int second=0)
 
void set (void)
 Set (update) the time with current time.
 
void set (const char *pointer, size_t size=0)
 Set time from a hh:mm:ss formatted string. More...
 
 Time (const time_t value)
 Create a time from the time portion of a time_t. More...
 
 Time (const tm_t *object)
 Create a time from the time portion of a date and time object. More...
 
 Time (const char *pointer, size_t size=0)
 Create a time from a hh:mm:ss formatted time string. More...
 
 Time (int hour, int minute, int second)
 Create a time from hours (0-23), minutes (0-59), and seconds (0-59). More...
 
 Time (const Time &object)
 Create a time object from another object. More...
 
 Time ()
 Create a time from current time.
 
virtual ~Time ()
 Destroy time object.
 

Static Public Attributes

static const long c_day
 Constant for number of seconds in a day.
 
static const long c_hour
 Constant for number of seconds in a hour.
 
static const long c_week
 Constant for number of seconds in a week.
 
static const size_t sz_string
 Size of time string field.
 

Protected Member Functions

virtual void update (void)
 

Protected Attributes

long seconds
 

Detailed Description

The Time class uses a integer representation of the current time.

This is then manipulated in several forms and may be exported as needed. The time object can represent an instance in time (hours, minutes, and seconds) in a 24 hour period or can represent a duration. Millisecond accuracy can be offered.

Author
Marcelo Dalmas mad@b.nosp@m.rasm.nosp@m.ap.co.nosp@m.m.br and David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org Integer based time class.

Definition at line 351 of file datetime.h.

Constructor & Destructor Documentation

◆ Time() [1/5]

ucommon::Time::Time ( const time_t  value)

Create a time from the time portion of a time_t.

Parameters
valueof time_t to use.

◆ Time() [2/5]

ucommon::Time::Time ( const tm_t object)

Create a time from the time portion of a date and time object.

Parameters
objectfrom DateTime::glt() or gmt().

◆ Time() [3/5]

ucommon::Time::Time ( const char *  pointer,
size_t  size = 0 
)

Create a time from a hh:mm:ss formatted time string.

Parameters
pointerto formatted time field.
sizeof field if not null terminated.

◆ Time() [4/5]

ucommon::Time::Time ( int  hour,
int  minute,
int  second 
)

Create a time from hours (0-23), minutes (0-59), and seconds (0-59).

Parameters
hourof time.
minuteof time.
secondof time.

◆ Time() [5/5]

ucommon::Time::Time ( const Time object)

Create a time object from another object.

Parameters
objectto copy.

Member Function Documentation

◆ get()

long ucommon::Time::get ( void  ) const

Get current time in seconds from midnight.

Returns
seconds from midnight.

◆ hour()

int ucommon::Time::hour ( void  ) const

Get hours from midnight.

Returns
hours from midnight.

◆ is_valid()

bool ucommon::Time::is_valid ( void  ) const

Check if time object had valid value.

Returns
true if object is valid.

◆ minute()

int ucommon::Time::minute ( void  ) const

Get minutes from current hour.

Returns
minutes from current hour.

◆ operator *()

long ucommon::Time::operator * ( ) const
inline

Get object time in seconds.

Returns
time in seconds.

Definition at line 523 of file datetime.h.

◆ operator bool()

ucommon::Time::operator bool ( ) const
inline

Check if time object has valid value for is() operator.

Returns
true if object is valid.

Definition at line 478 of file datetime.h.

◆ operator long()

ucommon::Time::operator long ( ) const
inline

Get time in seconds.

Returns
seconds.

Definition at line 515 of file datetime.h.

◆ operator!()

bool ucommon::Time::operator! ( ) const
inline

Check if time object has valid value for ! operator.

Returns
true if object is not valid.

Definition at line 486 of file datetime.h.

◆ operator!=()

bool ucommon::Time::operator!= ( const Time time) const

Compare time with another time to see if not same time.

Parameters
timeto compare with.
Returns
true if not same time.

◆ operator()()

stringref_t ucommon::Time::operator() ( ) const

Convert to standard 24 hour time string.

Returns
time string.

◆ operator+()

const Time ucommon::Time::operator+ ( long  seconds) const

Add seconds to the current time, wrap if 24 hours.

Parameters
secondsto add.
Returns
new time object with modified value.

◆ operator++()

Time& ucommon::Time::operator++ ( )

Incrememnt time by 1 second, wrap on 24 hour period.

Returns
modified instance of current time object.

◆ operator+=()

Time& ucommon::Time::operator+= ( long  seconds)

Increment time by specified seconds.

Wraps on 24 hour period.

Parameters
secondsto add to current time.
Returns
modified instance of current time object.

◆ operator-() [1/2]

long ucommon::Time::operator- ( const Time reference)

Get difference (in seconds) between two times.

Parameters
referencetime to get difference from.
Returns
difference in seconds.

◆ operator-() [2/2]

const Time ucommon::Time::operator- ( long  seconds) const

Subtract seconds to the current time, wrap if 24 hours.

Parameters
secondsto subtract.
Returns
new time object with modified value.

◆ operator--()

Time& ucommon::Time::operator-- ( )

Decrement time by 1 second, wrap on 24 hour period.

Returns
modified instance of current time object.

◆ operator-=()

Time& ucommon::Time::operator-= ( long  seconds)

Decrement time by specified seconds.

Wraps on 24 hour period.

Parameters
secondsto subtract from current time.
Returns
modified instance of current time object.

◆ operator<()

bool ucommon::Time::operator< ( const Time time) const

Compare time if earlier than another time.

Parameters
timeobject to compare with.
Returns
true if earlier than object.

◆ operator<=()

bool ucommon::Time::operator<= ( const Time time) const

Compare time if earlier than or equal to another time.

Parameters
timeobject to compare with.
Returns
true if earlier or same as object.

◆ operator=()

Time& ucommon::Time::operator= ( const Time time)

Assign a time as a copy of another time.

Parameters
timeto assign from.
Returns
time object that was assigned.

◆ operator==()

bool ucommon::Time::operator== ( const Time time) const

Compare time with another time to see if same time.

Parameters
timeto compare with.
Returns
true if same time.

◆ operator>()

bool ucommon::Time::operator> ( const Time time) const

Compare time if later than another time.

Parameters
timeobject to compare with.
Returns
true if later than object.

◆ operator>=()

bool ucommon::Time::operator>= ( const Time time) const

Compare time if later than or equal to another time.

Parameters
timeobject to compare with.
Returns
true if later than or same as object.

◆ put()

const char* ucommon::Time::put ( char *  buffer) const

Get a hh:mm:ss formatted string for current time.

Parameters
bufferto store time string in.
Returns
time string buffer or NULL if invalid.

◆ second()

int ucommon::Time::second ( void  ) const

Get seconds from current minute.

Returns
seconds from current minute.

◆ set()

void ucommon::Time::set ( const char *  pointer,
size_t  size = 0 
)

Set time from a hh:mm:ss formatted string.

Parameters
pointerto time field.
sizeof field if not null terminated.

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