Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes

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

Public Types

enum  index_t { year = 10, month, day, dow }
 

index elements.


Public Member Functions

 Date (time_t value)
 Create a julian date from a time_t type.
 Date (struct tm *object)
 Create a julian date from a local or gmt date and time.
 Date (int year, unsigned month=1, unsigned day=1)
 Create a julian date from an arbitrary year, month, and day.
 Date (const Date &object)
 Create a julian date object from another object.
 Date (const char *pointer, size_t size=0)
 Create a julian date from a ISO date string of a specified size.
 Date ()
 Construct a new julian date with today's date.
char * get (char *buffer) const
 Get a ISO string representation of the date (yyyy-mm-dd).
long get (void) const
 Get the date as a number for the object or 0 if invalid.
unsigned getDay (void) const
 Get the day of the month of the date.
unsigned getDayOfWeek (void) const
 Get the day of the week (0-7).
long getJulian (void)
 Get the julian number of a date.
unsigned getMonth (void) const
 Get the month of the date (1-12).
time_t getTime (void) const
 Get a time_t for the julian date if in time_t epoch.
int getYear (void) const
 Get the year of the date.
bool isValid (void) const
 Check if date is valid.
 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)
 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)
 Compare julian date if earlier than another date.
bool operator<= (const Date &date)
 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)
 Compare julian dates if same date.
bool operator> (const Date &date)
 Compare julian date if later than another date.
bool operator>= (const Date &date)
 Compare julian date if later than or equal to another date.
int operator[] (index_t component) const
 Access numeric components.
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.
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 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.

Definition at line 66 of file datetime.h.


Constructor & Destructor Documentation

ucc::Date::Date ( time_t  value  ) 

Create a julian date from a time_t type.

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

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

Parameters:
object from DateTime::glt() or gmt().
ucc::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.
ucc::Date::Date ( int  year,
unsigned  month = 1,
unsigned  day = 1 
)

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).
ucc::Date::Date ( const Date object  ) 

Create a julian date object from another object.

Parameters:
object to copy.

Member Function Documentation

char* ucc::Date::get ( char *  buffer  )  const

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

Parameters:
buffer to store string.
Returns:
string representation.
long ucc::Date::get ( void   )  const

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

Returns:
date as number.
unsigned ucc::Date::getDay ( void   )  const

Get the day of the month of the date.

Returns:
day of month
unsigned ucc::Date::getDayOfWeek ( void   )  const

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

Returns:
day of week
long ucc::Date::getJulian ( void   )  [inline]

Get the julian number of a date.

Returns:
julian number.

Definition at line 162 of file datetime.h.

unsigned ucc::Date::getMonth ( void   )  const

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

Returns:
month of year
time_t ucc::Date::getTime ( void   )  const

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

Returns:
time_t or -1 if out of range.
int ucc::Date::getYear ( void   )  const

Get the year of the date.

Returns:
year of the date
bool ucc::Date::isValid ( void   )  const

Check if date is valid.

Returns:
true if julian date is valid.
ucc::Date::operator bool (  )  const [inline]

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

Returns:
true if date is valid.

Definition at line 338 of file datetime.h.

ucc::Date::operator long (  )  const [inline]

Casting operator to return date as number.

Returns:
julian number.

Definition at line 206 of file datetime.h.

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

Check if julian date is not valid.

Returns:
true if date is invalid.

Definition at line 331 of file datetime.h.

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

Compare julian dates if not same date.

Parameters:
date to compare with.
Returns:
true if not same.
String ucc::Date::operator() (  )  const

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

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

Access julian value.

Returns:
julian number of object.

Definition at line 220 of file datetime.h.

Date ucc::Date::operator+ ( long  days  ) 

Add days to julian date in an expression.

Parameters:
days to add.
Returns:
new date object with modified days.
Date& ucc::Date::operator++ (  ) 

Increment date by one day.

Returns:
instance of current date object.
Date& ucc::Date::operator+= ( long  offset  ) 

Increment date by offset.

Parameters:
offset to add to julian date.
Returns:
instance of current date object.
Date ucc::Date::operator- ( long  days  ) 

Subtract days from a julian date in an expression.

Parameters:
days to subtract.
Returns:
new date object with modified days.
long ucc::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.

Definition at line 275 of file datetime.h.

Date& ucc::Date::operator-- (  ) 

Decrement date by one day.

Returns:
instance of current date object.
Date& ucc::Date::operator-= ( long  offset  ) 

Decrement date by offset.

Parameters:
offset to subtract from julian date.
Returns:
instance of current date object.
bool ucc::Date::operator< ( const Date date  ) 

Compare julian date if earlier than another date.

Parameters:
date to compare with.
Returns:
true if earlier.
bool ucc::Date::operator<= ( const Date date  ) 

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

Parameters:
date to compare with.
Returns:
true if earlier or same.
Date& ucc::Date::operator= ( const Date date  ) 

Assign date from another date object.

Parameters:
date object to assign from.
Returns:
current modified date object.
bool ucc::Date::operator== ( const Date date  ) 

Compare julian dates if same date.

Parameters:
date to compare with.
Returns:
true if same.
bool ucc::Date::operator> ( const Date date  ) 

Compare julian date if later than another date.

Parameters:
date to compare with.
Returns:
true if later.
bool ucc::Date::operator>= ( const Date date  ) 

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

Parameters:
date to compare with.
Returns:
true if later or same.
int ucc::Date::operator[] ( index_t  component  )  const

Access numeric components.

Parameters:
component to access.
Returns:
value of component.
void ucc::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.
virtual void ucc::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 ucc::DateNumber.


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