UCommon
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions
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 (const time_t time)
 Construct a date and time from C library time_t type. More...
 
 DateTime (const tm_t *tm)
 Construct a date and time from C library time structure. More...
 
 DateTime (const char *pointer, size_t size=0)
 Construct a date and time from ISO string buffer. More...
 
 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. More...
 
 DateTime (const DateTime &object)
 Create a datetime object from another object. More...
 
 DateTime ()
 Construct a new date and time object with current date and time.
 
stringref_t format (const char *strftime) const
 Return date and time formatted using strftime format values. More...
 
time_t get (void) const
 Get C library time_t type if object in C library epoch range. More...
 
bool is_valid (void) const
 Test if object is valid. More...
 
 operator bool () const
 Test is date and time is valid for is() operator. More...
 
 operator double () const
 Convert date and time to julian day number. More...
 
 operator long () const
 Casting operator to return date as number. More...
 
bool operator! () const
 Check if date and time is not valid. More...
 
bool operator!= (const DateTime &datetime) const
 Compare date and time with another date and time to see if not same. More...
 
const DateTime operator+ (long seconds) const
 Add seconds to datetime in an expression. More...
 
DateTimeoperator++ ()
 Add a day from the current date and time. More...
 
DateTimeoperator+= (long seconds)
 Add seconds to the current datetime object. More...
 
long operator- (const DateTime &datetime)
 Operator to compute number of days between two dates. More...
 
const DateTime operator- (long seconds) const
 Subtract seconds from datetime in an expression. More...
 
DateTimeoperator-- ()
 Subtract a day from the current date and time. More...
 
DateTimeoperator-= (long seconds)
 Subtract seconds from current datetime object. More...
 
bool operator< (const DateTime &datetime) const
 Compare date and time with another date and time to see if earlier. More...
 
bool operator<= (const DateTime &datetime) const
 Compare date and time with another date and time to see if earlier or the same. More...
 
DateTimeoperator= (const DateTime &datetime)
 Assign date and time from another datetime object. More...
 
bool operator== (const DateTime &datetime) const
 Compare date and time with another date and time to see if the same. More...
 
bool operator> (const DateTime &datetime) const
 Compare date and time with another date and time to see if later. More...
 
bool operator>= (const DateTime &datetime) const
 Compare date and time with another date and time to see if later or the same. More...
 
const char * put (char *buffer) const
 Get a ISO formatted date and time string for current object. More...
 
void set (void)
 Set (update) the date and time with current date and time.
 
virtual ~DateTime ()
 Destroy date and time object.
 
- Public Member Functions inherited from ucommon::Date
 Date (time_t value)
 Create a julian date from a time_t type. More...
 
 Date (const struct tm *object)
 Create a julian date from a local or gmt date and time. More...
 
 Date (const char *pointer, size_t size=0)
 Create a julian date from a ISO date string of a specified size. More...
 
 Date (int year, unsigned month, unsigned day)
 Create a julian date from an arbitrary year, month, and day. More...
 
 Date (const Date &object)
 Create a julian date object from another object. More...
 
 Date ()
 Construct a new julian date with today's date.
 
unsigned day (void) const
 Get the day of the month of the date. More...
 
unsigned dow (void) const
 Get the day of the week (0-7). More...
 
long get (void) const
 Get the date as a number for the object or 0 if invalid. More...
 
bool is_valid (void) const
 Check if date is valid. More...
 
unsigned month (void) const
 Get the month of the date (1-12). More...
 
long operator * () const
 Access julian value. More...
 
 operator bool () const
 Check if julian date is valid for is() expression. More...
 
 operator long () const
 Casting operator to return date as number. More...
 
bool operator! () const
 Check if julian date is not valid. More...
 
bool operator!= (const Date &date) const
 Compare julian dates if not same date. More...
 
stringref_t operator() () const
 Expression operator to return an ISO date string for the current julian date. More...
 
const Date operator+ (long days) const
 Add days to julian date in an expression. More...
 
Dateoperator++ ()
 Increment date by one day. More...
 
Dateoperator+= (long offset)
 Increment date by offset. More...
 
const Date operator- (long days) const
 Subtract days from a julian date in an expression. More...
 
long operator- (const Date &date)
 Operator to compute number of days between two dates. More...
 
Dateoperator-- ()
 Decrement date by one day. More...
 
Dateoperator-= (long offset)
 Decrement date by offset. More...
 
bool operator< (const Date &date) const
 Compare julian date if earlier than another date. More...
 
bool operator<= (const Date &date) const
 Compare julian date if earlier than or equal to another date. More...
 
Dateoperator= (const Date &date)
 Assign date from another date object. More...
 
bool operator== (const Date &date) const
 Compare julian dates if same date. More...
 
bool operator> (const Date &date) const
 Compare julian date if later than another date. More...
 
bool operator>= (const Date &date) const
 Compare julian date if later than or equal to another date. More...
 
const char * put (char *buffer) const
 Get a ISO string representation of the date (yyyy-mm-dd). More...
 
void set (void)
 Set (update) the date with current date.
 
void set (const char *pointer, size_t size=0)
 Set the julian date based on an ISO date string of specified size. More...
 
time_t timeref (void) const
 Get a time_t for the julian date if in time_t epoch. More...
 
int year (void) const
 Get the year of the date. More...
 
virtual ~Date ()
 Destroy julian date object.
 
- Public Member Functions inherited from ucommon::Time
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 Member Functions

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

Static Public Attributes

static const size_t sz_string
 Size of datetime string field.
 
- Static Public Attributes inherited from ucommon::Date
static const size_t sz_string
 Size of date string field.
 
- Static Public Attributes inherited from ucommon::Time
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)
 A method to use to "post" any changed values when shadowing a mixed object class. More...
 
- Protected Member Functions inherited from ucommon::Date
void set (long year, long month, long day)
 

Additional Inherited Members

- Protected Attributes inherited from ucommon::Date
long julian
 
- Protected Attributes inherited from ucommon::Time
long seconds
 

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@b.nosp@m.rasm.nosp@m.ap.co.nosp@m.m.br Integer based time class.
Examples
datetime.cpp.

Definition at line 618 of file datetime.h.

Constructor & Destructor Documentation

◆ DateTime() [1/5]

ucommon::DateTime::DateTime ( const time_t  time)

Construct a date and time from C library time_t type.

Parameters
timetype to make date and time from.

◆ DateTime() [2/5]

ucommon::DateTime::DateTime ( const tm_t tm)

Construct a date and time from C library time structure.

Parameters
tmstructure from C library (from glt or gmt).

◆ DateTime() [3/5]

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

Construct a date and time from ISO string buffer.

Parameters
pointerto string field holding date and time.
sizeof field if not null terminated string.

◆ DateTime() [4/5]

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
yearof object.
monthof object (1-12).
dayof month of object (1-31).
hourof object (0-23).
minuteof object (0-59).
secondof object (0-59).

◆ DateTime() [5/5]

ucommon::DateTime::DateTime ( const DateTime object)

Create a datetime object from another object.

Parameters
objectto copy.

Member Function Documentation

◆ format()

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

Return date and time formatted using strftime format values.

Parameters
strftimeformat to use.
Returns
String object with formatted time.

◆ get()

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.

◆ gmt()

static tm_t* ucommon::DateTime::gmt ( const 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
timeobject or NULL if using current time.
Returns
locked instance of struct tm object.

◆ is_valid()

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

Test if object is valid.

Returns
true if object is valid.

◆ local()

static tm_t* ucommon::DateTime::local ( const 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
timeobject or NULL if using current time.
Returns
locked instance of struct tm object.

◆ operator bool()

ucommon::DateTime::operator bool ( ) const

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

Returns
true if object is valid.

◆ operator double()

ucommon::DateTime::operator double ( ) const

Convert date and time to julian day number.

Returns
julian day number as a double.

◆ operator long()

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

Casting operator to return date as number.

Returns
date as a number.

Definition at line 813 of file datetime.h.

Here is the call graph for this function:

◆ operator!()

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

Check if date and time is not valid.

Returns
true if not valid.

◆ operator!=()

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

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

Parameters
datetimeto compare with.
Returns
true if not equal.

◆ operator+()

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

Add seconds to datetime in an expression.

Day overflows update julian date.

Parameters
secondsto add to datetime.
Returns
new modified datetime object.

◆ operator++()

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

Add a day from the current date and time.

Returns
datetime object reference that was modified.

◆ operator+=()

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

Add seconds to the current datetime object.

Day overflows update julian date.

Parameters
secondsto add to object.
Returns
modified datetime object.

◆ operator-() [1/2]

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

Operator to compute number of days between two dates.

Parameters
datetimeto offset from for computation.
Returns
number of days difference.

◆ operator-() [2/2]

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

Subtract seconds from datetime in an expression.

Day underflows update julian date.

Parameters
secondsto subtract from datetime.
Returns
new modified datetime object.

◆ operator--()

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

Subtract a day from the current date and time.

Returns
datetime object reference that was modified.

◆ operator-=()

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

Subtract seconds from current datetime object.

Day underflows update julian date.

Parameters
secondsto subtract from object.
Returns
modified datetime object.

◆ operator<()

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

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

Parameters
datetimeto compare with.
Returns
true if earlier.

◆ operator<=()

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
datetimeto compare with.
Returns
true if earlier or equal.

◆ operator=()

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

Assign date and time from another datetime object.

Parameters
datetimeobject to assign from.
Returns
assigned datetime object.

◆ operator==()

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

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

Parameters
datetimeto compare with.
Returns
true if equal.

◆ operator>()

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

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

Parameters
datetimeto compare with.
Returns
true if later.

◆ operator>=()

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
datetimeto compare with.
Returns
true if later or equal.

◆ put()

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

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

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

◆ release()

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

Release a struct tm object from glt or gmt.

Parameters
objectto release.

◆ update()

virtual void ucommon::DateTime::update ( void  )
protectedvirtual

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: