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 Date:
Inheritance graph
[legend]

Public Member Functions

 Date (const Date &object)
 Date (int y, unsigned m, unsigned d)
 Date (const char *ptr, size_t size=0)
 Date (struct tm *object)
 Date (time_t value)
 Date ()
 Construct a new julian date with today's date.
 Date (const Date &object)
 Create a julian date object from another object.
 Date (int year, unsigned month, unsigned day)
 Create a julian date from an arbitrary year, month, and day.
 Date (const char *pointer, size_t size=0)
 Create a julian date from a ISO date string of a specified size.
 Date (struct tm *object)
 Create a julian date from a local or gmt date and time.
 Date (time_t value)
 Create a julian date from a time_t type.
unsigned day (void) const
 Get the day of the month of the date.
unsigned dow (void) const
 Get the day of the week (0-7).
const char * get (char *buffer) const
long get (void) const
 Get the date as a number for the object or 0 if invalid.
unsigned getDay (void) const
unsigned getDayOfWeek (void) const
long getJulian (void) const
unsigned getMonth (void) const
time_t getTime (void) const
int getYear (void) const
bool is_valid (void) const
 Check if date is valid.
bool isValid (void) const
unsigned month (void) const
 Get the month of the date (1-12).
 operator bool () const
 Check if julian date is valid for is() expression.
 operator long () const
 Casting operator to return date as number.
bool operator! () const
 Check if julian date is not valid.
bool operator!= (const Date &date) const
 Compare julian dates if not same date.
String operator() () const
 Expression operator to return an ISO date string for the current julian date.
long operator* () const
 Access julian value.
Date operator+ (long days)
 Add days to julian date in an expression.
Dateoperator++ ()
 Increment date by one day.
Dateoperator+= (long offset)
 Increment date by offset.
long operator- (const Date &date)
 Operator to compute number of days between two dates.
Date operator- (long days)
 Subtract days from a julian date in an expression.
Dateoperator-- ()
 Decrement date by one day.
Dateoperator-= (long offset)
 Decrement date by offset.
bool operator< (const Date &date) const
 Compare julian date if earlier than another date.
bool operator<= (const Date &date) const
 Compare julian date if earlier than or equal to another date.
Dateoperator= (const Date &date)
 Assign date from another date object.
bool operator== (const Date &date) const
 Compare julian dates if same date.
bool operator> (const Date &date) const
 Compare julian date if later than another date.
bool operator>= (const Date &date) const
 Compare julian date if later than or equal to another date.
const char * put (char *buffer) const
 Get a ISO string representation of the date (yyyy-mm-dd).
void set (const char *pointer, size_t size=0)
 Set the julian date based on an ISO date string of specified size.
void set (void)
 Set (update) the date with current date.
time_t timeref (void) const
 Get a time_t for the julian date if in time_t epoch.
int year (void) const
 Get the year of the date.
virtual ~Date ()
 Destroy julian date object.

Static Public Attributes

static const size_t sz_string
 Size of date string field.

Protected Member Functions

void fromJulian (char *buf) const
void set (long year, long month, long day)
void toJulian (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.

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@ostel.com> julian number based date class.
Examples:

datetime.cpp.

Definition at line 78 of file datetime.h.


Constructor & Destructor Documentation

Date::Date ( time_t  value  ) 

Create a julian date from a time_t type.

Parameters:
value from time()
Date::Date ( struct tm *  object  ) 

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

Parameters:
object from DateTime::glt() or gmt().
Date::Date ( const char *  pointer,
size_t  size = 0 
)

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

Parameters:
pointer to ISO date string.
size of date field if not null terminated.
Date::Date ( int  year,
unsigned  month,
unsigned  day 
)

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

Parameters:
year of date.
month of date (1-12).
day of month (1-31).
Date::Date ( const Date object  ) 

Create a julian date object from another object.

Parameters:
object to copy.

Member Function Documentation

unsigned Date::day ( void   )  const

Get the day of the month of the date.

Returns:
day of month
Examples:
datetime.cpp.
unsigned Date::dow ( void   )  const

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

Returns:
day of week
Examples:
datetime.cpp.
long Date::get ( void   )  const

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

Returns:
date as number.

Reimplemented in DateTime.

Examples:
datetime.cpp.
bool Date::is_valid ( void   )  const

Check if date is valid.

Returns:
true if julian date is valid.

Reimplemented in DateTime.

unsigned Date::month ( void   )  const

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

Returns:
month of year
Examples:
datetime.cpp.
Date::operator bool (  )  const [inline]

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

Returns:
true if date is valid.

Reimplemented in DateTime.

Definition at line 330 of file datetime.h.

Date::operator long (  )  const [inline]

Casting operator to return date as number.

Returns:
julian number.

Reimplemented in DateTime.

Definition at line 205 of file datetime.h.

bool Date::operator! (  )  const [inline]

Check if julian date is not valid.

Returns:
true if date is invalid.

Reimplemented in DateTime.

Definition at line 323 of file datetime.h.

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

Compare julian dates if not same date.

Parameters:
date to compare with.
Returns:
true if not same.

Reimplemented in DateTime.

String Date::operator() (  )  const

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

Returns:
ISO date string.
long Date::operator* (  )  const [inline]

Access julian value.

Returns:
julian number of object.

Definition at line 212 of file datetime.h.

Date Date::operator+ ( long  days  ) 

Add days to julian date in an expression.

Parameters:
days to add.
Returns:
new date object with modified days.

Reimplemented in DateTime.

Date& Date::operator++ (  ) 

Increment date by one day.

Returns:
instance of current date object.

Reimplemented in DateTime.

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

Increment date by offset.

Parameters:
offset to add to julian date.
Returns:
instance of current date object.

Reimplemented in DateTime.

long Date::operator- ( const Date date  )  [inline]

Operator to compute number of days between two dates.

Parameters:
date offset for computation.
Returns:
number of days difference.

Reimplemented in DateTime.

Definition at line 267 of file datetime.h.

Date Date::operator- ( long  days  ) 

Subtract days from a julian date in an expression.

Parameters:
days to subtract.
Returns:
new date object with modified days.

Reimplemented in DateTime.

Date& Date::operator-- (  ) 

Decrement date by one day.

Returns:
instance of current date object.

Reimplemented in DateTime.

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

Decrement date by offset.

Parameters:
offset to subtract from julian date.
Returns:
instance of current date object.

Reimplemented in DateTime.

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

Compare julian date if earlier than another date.

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

Reimplemented in DateTime.

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

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

Parameters:
date to compare with.
Returns:
true if earlier or same.

Reimplemented in DateTime.

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

Assign date from another date object.

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

Reimplemented in DateTime.

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

Compare julian dates if same date.

Parameters:
date to compare with.
Returns:
true if same.

Reimplemented in DateTime.

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

Compare julian date if later than another date.

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

Reimplemented in DateTime.

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

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

Parameters:
date to compare with.
Returns:
true if later or same.

Reimplemented in DateTime.

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

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

Parameters:
buffer to store string.
Returns:
string representation.

Reimplemented in DateTime.

Examples:
datetime.cpp.
void Date::set ( const char *  pointer,
size_t  size = 0 
)

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

Parameters:
pointer to date string field.
size of field if not null terminated.
time_t 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.
virtual void Date::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 in DateTime, DateTimeString, and DateNumber.

int 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 files:

Generated on 24 Sep 2014 for ucommon by  doxygen 1.6.1