ucommon
Public Types | 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 Types

enum  index_t { hour = 20, minute, second }
 Component access index.

Public Member Functions

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

Static Public Attributes

static size_t sz_string
 Size of time string field.

Protected Member Functions

void fromSeconds (char *buf)
void toSeconds (int hour, int minute=0, int second=0)
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@brasmap.com.br> and David Sugar <dyfet@gnutelephony.org> Integer based time class.

Definition at line 360 of file datetime.h.


Constructor & Destructor Documentation

ucommon::Time::Time ( time_t  value)

Create a time from the time portion of a time_t.

Parameters:
valueof time_t to use.
ucommon::Time::Time ( tm_t object)

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

Parameters:
objectfrom DateTime::glt() or gmt().
ucommon::Time::Time ( 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.
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.
ucommon::Time::Time ( Time object)

Create a time object from another object.

Parameters:
objectto copy.

Member Function Documentation

long ucommon::Time::get ( void  )

Get current time in seconds from midnight.

Returns:
seconds from midnight.

Reimplemented in ucommon::DateTime.

char* ucommon::Time::get ( char *  buffer)

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

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

Reimplemented in ucommon::DateTime.

int ucommon::Time::getHour ( void  )

Get hours from midnight.

Returns:
hours from midnight.
int ucommon::Time::getMinute ( void  )

Get minutes from current hour.

Returns:
minutes from current hour.
int ucommon::Time::getSecond ( void  )

Get seconds from current minute.

Returns:
seconds from current minute.
bool ucommon::Time::isValid ( void  )

Check if time object had valid value.

Returns:
true if object is valid.

Reimplemented in ucommon::DateTime.

ucommon::Time::operator bool ( ) [inline]

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

Returns:
true if object is valid.

Reimplemented in ucommon::DateTime.

Definition at line 477 of file datetime.h.

ucommon::Time::operator long ( ) [inline]

Get time in seconds.

Returns:
seconds.

Reimplemented in ucommon::DateTime.

Definition at line 512 of file datetime.h.

bool ucommon::Time::operator! ( ) [inline]

Check if time object has valid value for ! operator.

Returns:
true if object is not valid.

Reimplemented in ucommon::DateTime.

Definition at line 484 of file datetime.h.

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

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

Parameters:
timeto compare with.
Returns:
true if not same time.
String ucommon::Time::operator() ( )

Convert to standard 24 hour time string.

Returns:
time string.
long ucommon::Time::operator* ( ) [inline]

Get object time in seconds.

Returns:
time in seconds.

Definition at line 519 of file datetime.h.

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

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

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

Reimplemented in ucommon::DateTime.

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

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

Returns:
modified instance of current time object.

Reimplemented in ucommon::DateTime.

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.

Reimplemented in ucommon::DateTime.

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

Get difference (in seconds) between two times.

Parameters:
referencetime to get difference from.
Returns:
difference in seconds.
Time ucommon::Time::operator- ( long  seconds)

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

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

Reimplemented in ucommon::DateTime.

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

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

Returns:
modified instance of current time object.

Reimplemented in ucommon::DateTime.

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.

Reimplemented in ucommon::DateTime.

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

Compare time if earlier than another time.

Parameters:
timeobject to compare with.
Returns:
true if earlier than object.
bool ucommon::Time::operator<= ( Time time)

Compare time if earlier than or equal to another time.

Parameters:
timeobject to compare with.
Returns:
true if earlier or same as object.
Time& ucommon::Time::operator= ( Time time)

Assign a time as a copy of another time.

Parameters:
timeto assign from.
Returns:
time object that was assigned.
bool ucommon::Time::operator== ( Time time)

Compare time with another time to see if same time.

Parameters:
timeto compare with.
Returns:
true if same time.
bool ucommon::Time::operator> ( Time time)

Compare time if later than another time.

Parameters:
timeobject to compare with.
Returns:
true if later than object.
bool ucommon::Time::operator>= ( Time time)

Compare time if later than or equal to another time.

Parameters:
timeobject to compare with.
Returns:
true if later than or same as object.
int ucommon::Time::operator[] ( index_t  component)

Get component of time object.

Parameters:
componentindex.
Returns:
value of component.
void ucommon::Time::set ( 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: