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

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

#include <datetime.h>

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

Public Member Functions

 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.
 

Static Public Attributes

static const size_t sz_string
 Size of date string field.
 

Protected Member Functions

void set (long year, long month, long day)
 
virtual void update (void)
 A method to use to "post" any changed values when shadowing a mixed object class. More...
 

Protected Attributes

long julian
 

Detailed Description

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

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

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m julian number based date class.
Examples
datetime.cpp.

Definition at line 79 of file datetime.h.

Constructor & Destructor Documentation

◆ Date() [1/5]

ucommon::Date::Date ( time_t  value)

Create a julian date from a time_t type.

Parameters
valuefrom time()

◆ Date() [2/5]

ucommon::Date::Date ( const struct tm *  object)

Create a julian date from a local or gmt date and time.

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

◆ Date() [3/5]

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

Create a julian date from a ISO date string of a specified size.

Parameters
pointerto ISO date string.
sizeof date field if not null terminated.

◆ Date() [4/5]

ucommon::Date::Date ( int  year,
unsigned  month,
unsigned  day 
)

Create a julian date from an arbitrary year, month, and day.

Parameters
yearof date.
monthof date (1-12).
dayof month (1-31).

◆ Date() [5/5]

ucommon::Date::Date ( const Date object)

Create a julian date object from another object.

Parameters
objectto copy.

Member Function Documentation

◆ day()

unsigned ucommon::Date::day ( void  ) const

Get the day of the month of the date.

Returns
day of month
Examples
datetime.cpp.

◆ dow()

unsigned ucommon::Date::dow ( void  ) const

Get the day of the week (0-7).

Returns
day of week
Examples
datetime.cpp.

◆ get()

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

Get the date as a number for the object or 0 if invalid.

Returns
date as number.
Examples
datetime.cpp.

◆ is_valid()

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

Check if date is valid.

Returns
true if julian date is valid.

◆ month()

unsigned ucommon::Date::month ( void  ) const

Get the month of the date (1-12).

Returns
month of year
Examples
datetime.cpp.

◆ operator *()

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

Access julian value.

Returns
julian number of object.

Definition at line 214 of file datetime.h.

◆ operator bool()

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

Check if julian date is valid for is() expression.

Returns
true if date is valid.

Definition at line 335 of file datetime.h.

◆ operator long()

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

Casting operator to return date as number.

Returns
julian number.

Definition at line 206 of file datetime.h.

◆ operator!()

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

Check if julian date is not valid.

Returns
true if date is invalid.

Definition at line 327 of file datetime.h.

◆ operator!=()

bool ucommon::Date::operator!= ( const Date date) const

Compare julian dates if not same date.

Parameters
dateto compare with.
Returns
true if not same.

◆ operator()()

stringref_t ucommon::Date::operator() ( ) const

Expression operator to return an ISO date string for the current julian date.

Returns
ISO date string.

◆ operator+()

const Date ucommon::Date::operator+ ( long  days) const

Add days to julian date in an expression.

Parameters
daysto add.
Returns
new date object with modified days.

◆ operator++()

Date& ucommon::Date::operator++ ( )

Increment date by one day.

Returns
instance of current date object.

◆ operator+=()

Date& ucommon::Date::operator+= ( long  offset)

Increment date by offset.

Parameters
offsetto add to julian date.
Returns
instance of current date object.

◆ operator-() [1/2]

const Date ucommon::Date::operator- ( long  days) const

Subtract days from a julian date in an expression.

Parameters
daysto subtract.
Returns
new date object with modified days.

◆ operator-() [2/2]

long ucommon::Date::operator- ( const Date date)
inline

Operator to compute number of days between two dates.

Parameters
dateoffset for computation.
Returns
number of days difference.

Definition at line 270 of file datetime.h.

◆ operator--()

Date& ucommon::Date::operator-- ( )

Decrement date by one day.

Returns
instance of current date object.

◆ operator-=()

Date& ucommon::Date::operator-= ( long  offset)

Decrement date by offset.

Parameters
offsetto subtract from julian date.
Returns
instance of current date object.

◆ operator<()

bool ucommon::Date::operator< ( const Date date) const

Compare julian date if earlier than another date.

Parameters
dateto compare with.
Returns
true if earlier.

◆ operator<=()

bool ucommon::Date::operator<= ( const Date date) const

Compare julian date if earlier than or equal to another date.

Parameters
dateto compare with.
Returns
true if earlier or same.

◆ operator=()

Date& ucommon::Date::operator= ( const Date date)

Assign date from another date object.

Parameters
dateobject to assign from.
Returns
current modified date object.

◆ operator==()

bool ucommon::Date::operator== ( const Date date) const

Compare julian dates if same date.

Parameters
dateto compare with.
Returns
true if same.

◆ operator>()

bool ucommon::Date::operator> ( const Date date) const

Compare julian date if later than another date.

Parameters
dateto compare with.
Returns
true if later.

◆ operator>=()

bool ucommon::Date::operator>= ( const Date date) const

Compare julian date if later than or equal to another date.

Parameters
dateto compare with.
Returns
true if later or same.

◆ put()

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

Get a ISO string representation of the date (yyyy-mm-dd).

Parameters
bufferto store string.
Returns
string representation.
Examples
datetime.cpp.

◆ set()

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

Set the julian date based on an ISO date string of specified size.

Parameters
pointerto date string field.
sizeof field if not null terminated.

◆ timeref()

time_t ucommon::Date::timeref ( void  ) const

Get a time_t for the julian date if in time_t epoch.

Returns
time_t or -1 if out of range.
Examples
datetime.cpp.

◆ update()

virtual void ucommon::Date::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 in ucommon::DateNumber, ucommon::DateTimeString, and ucommon::DateTime.

◆ year()

int ucommon::Date::year ( void  ) const

Get the year of the date.

Returns
year of the date
Examples
datetime.cpp.

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