ucommon::DateTime Class Reference

The Datetime class uses a julian date representation of the current year, month, and day and a integer representation of the current time. More...

#include <datetime.h>

Inheritance diagram for ucommon::DateTime:
Inheritance graph
[legend]
Collaboration diagram for ucommon::DateTime:
Collaboration graph
[legend]

Public Member Functions

 DateTime ()
 Construct a new date and time object with current date and time.
 DateTime (const DateTime &object)
 Create a datetime object from another object.
 DateTime (int year, unsigned month, unsigned day, int hour=0, int minute=0, int second=0)
 Construct a date and time object from explicit date and time values.
 DateTime (const char *pointer, size_t size=0)
 Construct a date and time from ISO string buffer.
 DateTime (tm_t *tm)
 Construct a date and time from C library time structure.
 DateTime (time_t time)
 Construct a date and time from C library time_t type.
String format (const char *strftime) const
 Return date and time formatted using strftime format values.
time_t get (void) const
 Get C library time_t type if object in C library epoch range.
bool is_valid (void) const
 Test if object is valid.
 operator bool () const
 Test is date and time is valid for is() operator.
 operator double () const
 Convert date and time to julian day number.
 operator long () const
 Casting operator to return date as number.
bool operator! () const
 Check if date and time is not valid.
bool operator!= (const DateTime &datetime) const
 Compare date and time with another date and time to see if not same.
DateTime operator+ (long seconds)
 Add seconds to datetime in an expression.
DateTimeoperator++ ()
 Add a day from the current date and time.
DateTimeoperator+= (long seconds)
 Add seconds to the current datetime object.
DateTime operator- (long seconds)
 Subtract seconds from datetime in an expression.
long operator- (const DateTime &datetime)
 Operator to compute number of days between two dates.
DateTimeoperator-- ()
 Subtract a day from the current date and time.
DateTimeoperator-= (long seconds)
 Subtract seconds from current datetime object.
bool operator< (const DateTime &datetime) const
 Compare date and time with another date and time to see if earlier.
bool operator<= (const DateTime &datetime) const
 Compare date and time with another date and time to see if earlier or the same.
DateTimeoperator= (const DateTime &datetime)
 Assign date and time from another datetime object.
bool operator== (const DateTime &datetime) const
 Compare date and time with another date and time to see if the same.
bool operator> (const DateTime &datetime) const
 Compare date and time with another date and time to see if later.
bool operator>= (const DateTime &datetime) const
 Compare date and time with another date and time to see if later or the same.
const char * put (char *buffer) const
 Get a ISO formatted date and time string for current object.
void set (void)
 Set (update) the date and time with current date and time.
virtual ~DateTime ()
 Destroy date and time object.

Static Public Member Functions

static tm_tgmt (time_t *time=NULL)
 Fetch an instance of time converted to gmt.
static tm_tlocal (time_t *time=NULL)
 Fetch an instance of time converted to local time.
static void release (tm_t *object)
 Release a struct tm object from glt or gmt.

Static Public Attributes

static const size_t sz_string
 Size of datetime string field.

Protected Member Functions

void update (void)
 A method to use to "post" any changed values when shadowing a mixed object class.

Detailed Description

The Datetime class uses a julian date representation of the current year, month, and day and a integer representation of the current time.

This is then manipulated in several forms and may be exported as needed.

Author:
Marcelo Dalmas <mad@brasmap.com.br> Integer based time class.

Definition at line 608 of file datetime.h.


Constructor & Destructor Documentation

ucommon::DateTime::DateTime ( time_t  time  ) 

Construct a date and time from C library time_t type.

Parameters:
time type to make date and time from.
ucommon::DateTime::DateTime ( tm_t tm  ) 

Construct a date and time from C library time structure.

Parameters:
tm structure from C library (from glt or gmt).
ucommon::DateTime::DateTime ( const char *  pointer,
size_t  size = 0 
)

Construct a date and time from ISO string buffer.

Parameters:
pointer to string field holding date and time.
size of field if not null terminated string.
ucommon::DateTime::DateTime ( int  year,
unsigned  month,
unsigned  day,
int  hour = 0,
int  minute = 0,
int  second = 0 
)

Construct a date and time object from explicit date and time values.

Parameters:
year of object.
month of object (1-12).
day of month of object (1-31).
hour of object (0-23).
minute of object (0-59).
second of object (0-59).
ucommon::DateTime::DateTime ( const DateTime object  ) 

Create a datetime object from another object.

Parameters:
object to copy.

Member Function Documentation

String ucommon::DateTime::format ( const char *  strftime  )  const

Return date and time formatted using strftime format values.

Parameters:
strftime format to use.
Returns:
String object with formatted time.
time_t ucommon::DateTime::get ( void   )  const

Get C library time_t type if object in C library epoch range.

Returns:
time in seconds from epoch or ~0l if out of range.

Reimplemented from ucommon::Date.

static tm_t* ucommon::DateTime::gmt ( time_t *  time = NULL  )  [static]

Fetch an instance of time converted to gmt.

If the gmtime abi is not re-entrant, than a lock is held, otherwise a unique object is returned. In either case, when you are done, you must release the object.

Parameters:
time object or NULL if using current time.
Returns:
locked instance of struct tm object.
bool ucommon::DateTime::is_valid ( void   )  const

Test if object is valid.

Returns:
true if object is valid.

Reimplemented from ucommon::Date.

static tm_t* ucommon::DateTime::local ( time_t *  time = NULL  )  [static]

Fetch an instance of time converted to local time.

If the localtime abi is not re-entrant, than a lock is held, otherwise a unique object is returned. In either case, when you are done, you must release the object.

Parameters:
time object or NULL if using current time.
Returns:
locked instance of struct tm object.
ucommon::DateTime::operator bool (  )  const

Test is date and time is valid for is() operator.

Returns:
true if object is valid.

Reimplemented from ucommon::Date.

ucommon::DateTime::operator double (  )  const

Convert date and time to julian day number.

Returns:
julian day number as a double.
ucommon::DateTime::operator long (  )  const [inline]

Casting operator to return date as number.

Returns:
date as a number.

Reimplemented from ucommon::Date.

Definition at line 803 of file datetime.h.

bool ucommon::DateTime::operator! (  )  const

Check if date and time is not valid.

Returns:
true if not valid.

Reimplemented from ucommon::Date.

bool ucommon::DateTime::operator!= ( const DateTime datetime  )  const

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

Parameters:
datetime to compare with.
Returns:
true if not equal.

Reimplemented from ucommon::Date.

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

Add seconds to datetime in an expression.

Day overflows update julian date.

Parameters:
seconds to add to datetime.
Returns:
new modified datetime object.

Reimplemented from ucommon::Date.

DateTime& ucommon::DateTime::operator++ (  ) 

Add a day from the current date and time.

Returns:
datetime object reference that was modified.

Reimplemented from ucommon::Date.

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

Add seconds to the current datetime object.

Day overflows update julian date.

Parameters:
seconds to add to object.
Returns:
modified datetime object.

Reimplemented from ucommon::Date.

DateTime ucommon::DateTime::operator- ( long  seconds  ) 

Subtract seconds from datetime in an expression.

Day underflows update julian date.

Parameters:
seconds to subtract from datetime.
Returns:
new modified datetime object.

Reimplemented from ucommon::Date.

long ucommon::DateTime::operator- ( const DateTime datetime  ) 

Operator to compute number of days between two dates.

Parameters:
datetime to offset from for computation.
Returns:
number of days difference.

Reimplemented from ucommon::Date.

DateTime& ucommon::DateTime::operator-- (  ) 

Subtract a day from the current date and time.

Returns:
datetime object reference that was modified.

Reimplemented from ucommon::Date.

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

Subtract seconds from current datetime object.

Day underflows update julian date.

Parameters:
seconds to subtract from object.
Returns:
modified datetime object.

Reimplemented from ucommon::Date.

bool ucommon::DateTime::operator< ( const DateTime datetime  )  const

Compare date and time with another date and time to see if earlier.

Parameters:
datetime to compare with.
Returns:
true if earlier.

Reimplemented from ucommon::Date.

bool ucommon::DateTime::operator<= ( const DateTime datetime  )  const

Compare date and time with another date and time to see if earlier or the same.

Parameters:
datetime to compare with.
Returns:
true if earlier or equal.

Reimplemented from ucommon::Date.

DateTime& ucommon::DateTime::operator= ( const DateTime datetime  ) 

Assign date and time from another datetime object.

Parameters:
datetime object to assign from.
Returns:
assigned datetime object.

Reimplemented from ucommon::Date.

bool ucommon::DateTime::operator== ( const DateTime datetime  )  const

Compare date and time with another date and time to see if the same.

Parameters:
datetime to compare with.
Returns:
true if equal.

Reimplemented from ucommon::Date.

bool ucommon::DateTime::operator> ( const DateTime datetime  )  const

Compare date and time with another date and time to see if later.

Parameters:
datetime to compare with.
Returns:
true if later.

Reimplemented from ucommon::Date.

bool ucommon::DateTime::operator>= ( const DateTime datetime  )  const

Compare date and time with another date and time to see if later or the same.

Parameters:
datetime to compare with.
Returns:
true if later or equal.

Reimplemented from ucommon::Date.

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

Get a ISO formatted date and time string for current object.

Parameters:
buffer to store date and time in (yyyy-mm-dd hh:mm:ss).
Returns:
string buffer if object is valid.

Reimplemented from ucommon::Date.

static void ucommon::DateTime::release ( tm_t object  )  [static]

Release a struct tm object from glt or gmt.

Parameters:
object to release.
void ucommon::DateTime::update ( void   )  [protected, virtual]

A method to use to "post" any changed values when shadowing a mixed object class.

This is used by DateNumber and string classes.

Reimplemented from ucommon::Date.

Reimplemented in ucommon::DateTimeString.


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

Generated on 30 Jul 2013 for UCommon by  doxygen 1.6.1