Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Date Class Reference

Date class for YMD and julian dates. More...

#include <Date.h>

Inheritance diagram for Date:

DateZulu SimDate List of all members.

Public Types

typedef sint32 julian_t
typedef uint08 day_t
typedef uint08 weekday_t
typedef uint08 month_t
typedef sint16 year_t
enum  WEEKDAY {
  MONDAY = 1, TUESDAY = 2, WEDNESDAY = 3, THURSDAY = 4,
  FRIDAY = 5, SATURDAY = 6, SUNDAY = 7
}
enum  MONTH {
  JANUARY = 1, FEBRUARY = 2, MARCH = 3, APRIL = 4,
  MAY = 5, JUNE = 6, JULY = 7, AUGUST = 8,
  SEPTEMBER = 9, OCTOBER = 10, NOVEMBER = 11, DECEMBER = 12
}

Public Methods

 Date ()
 Default constructor, sets date to Julian day 0 (January 1, 4713 BCE).

 Date (year_t year, month_t month, day_t day)
 Construct a Date from year, month, and day.

 Date (julian_t julian)
 Construct a Date from a Julian day.

 Date (const Date &d)
 Copy constructor.

const Date & operator= (const Date &d)
 Assignment.

bool isLeap () const
 Returns true if this is a leap year.

weekday_t getWeekday () const
 Get the day of the week as an integer (1=MONDAY..7=SUNDAY).

month_t getMonth () const
 Get the month of the year as an integer (1..12).

month_t getDay () const
 Get the day of the month (1..).

year_t getYear () const
 Get the year.

julian_t getJulian () const
 Get the Julian day (as an integer).

const char * getMonthName () const
 Get the full month name (e.g.

const char * getMonthShortName () const
 Get the abbreviated month name (e.g.

const char * getWeekdayName () const
 Get the full day of the week name (e.g.

const char * getWeekdayShortName () const
 Get the abbreviated day of the week name (e.g.

void setJulian (julian_t j)
 Set the Julian day.

int getDayOfYear () const
 Get the day of the year (1..).

int getMondayWeekOfYear () const
 Get the week of the year for weeks starting on Monday.

int getSundayWeekOfYear () const
 Get the week of the year for weeks starting on Sunday.

bool isFirstOfMonth () const
 Returns true if it is the first day of the month (i.e.

bool isLastOfMonth () const
 Returns true if it is the last day of the month.

void addDays (int ndays)
 Add a number of days to the date.

void subtractDays (int ndays)
 Subtract a number of days from the date.

void addMonths (int nmonths)
 Add a number of months to the date.

void subtractMonths (int nmonths)
 Subtract a number of months to the date.

void addYears (int nyears)
 Add a number of years to the date.

void subtractYears (int nyears)
 Subtract a number of years to the date.

virtual int compare (const Date &other) const
 Compare with another Date.

void convert (struct tm *tm) const
 Convert the date to a struct tm (time fields are set to zero).

std::string formatString (const char *format) const
 Convert the date to a string using strftime formatting.

virtual std::string asString () const
 Return a string representation of the date.

virtual std::string typeString () const
 Return a string representation of the type.


Static Public Methods

bool validYMD (year_t year, month_t month, day_t day)
 Check if a given (year, month, day) exists.

bool isLeap (year_t year)
 Returns true if the year is a leap year.

int getDaysInMonth (month_t month, year_t year)
 Get the number of days in a month.

int getWeeksInYear (year_t year)
 Get the number of weeks in a year (for weeks starting on Monday).

int getSundayWeeksInYear (year_t year)
 Get the number of weeks in a year (for weeks starting on Sunday).

int compare (const Date &a, const Date &b)
 Compare two dates.


Detailed Description

Date class for YMD and julian dates.

Author:
Mark Rose <mrose@stm.lbl.gov>
Note:
Many of these routines borrow heavily from the GDate implementation in GLib (Copyright 1995-1997 Peter Mattis, Spencer Kimball, and Josh MacDonald). Code derived from from GLib is used under the terms of the GNU General Public License, as allowed by the GNU Lesser General Public License.


Member Typedef Documentation

typedef uint08 Date::day_t
 

typedef sint32 Date::julian_t
 

typedef uint08 Date::month_t
 

typedef uint08 Date::weekday_t
 

typedef sint16 Date::year_t
 


Member Enumeration Documentation

enum Date::MONTH
 

Enumeration values:
JANUARY 
FEBRUARY 
MARCH 
APRIL 
MAY 
JUNE 
JULY 
AUGUST 
SEPTEMBER 
OCTOBER 
NOVEMBER 
DECEMBER 

enum Date::WEEKDAY
 

Enumeration values:
MONDAY 
TUESDAY 
WEDNESDAY 
THURSDAY 
FRIDAY 
SATURDAY 
SUNDAY 


Constructor & Destructor Documentation

Date::Date   [inline]
 

Default constructor, sets date to Julian day 0 (January 1, 4713 BCE).

Date::Date year_t    year,
month_t    month,
day_t    day
 

Construct a Date from year, month, and day.

Date::Date julian_t    julian [inline]
 

Construct a Date from a Julian day.

Date::Date const Date &    d [inline]
 

Copy constructor.


Member Function Documentation

void Date::addDays int    ndays [inline]
 

Add a number of days to the date.

void Date::addMonths int    nmonths
 

Add a number of months to the date.

The day will be truncated to fit within the new month.

void Date::addYears int    nyears
 

Add a number of years to the date.

February 29 change to February 28 for non-leap years.

virtual std::string Date::asString   const [inline, virtual]
 

Return a string representation of the date.

Returns:
a string of the form "YYYY/MM/DD"

Reimplemented in DateZulu, and SimDate.

virtual int Date::compare const Date &    other const [inline, virtual]
 

Compare with another Date.

Returns:
+1 if this > other, -1 if this < other, and 0 if the dates are equal.

int Date::compare const Date &    a,
const Date &    b
[static]
 

Compare two dates.

Returns:
+1 if a > b, -1 if a < b, or 0 if a == b.

void Date::convert struct tm *    tm const
 

Convert the date to a struct tm (time fields are set to zero).

std::string Date::formatString const char *    format const
 

Convert the date to a string using strftime formatting.

month_t Date::getDay   const [inline]
 

Get the day of the month (1..).

int Date::getDayOfYear   const [inline]
 

Get the day of the year (1..).

int Date::getDaysInMonth month_t    month,
year_t    year
[static]
 

Get the number of days in a month.

julian_t Date::getJulian   const [inline]
 

Get the Julian day (as an integer).

int Date::getMondayWeekOfYear  
 

Get the week of the year for weeks starting on Monday.

month_t Date::getMonth   const [inline]
 

Get the month of the year as an integer (1..12).

const char * Date::getMonthName  
 

Get the full month name (e.g.

"January").

const char * Date::getMonthShortName  
 

Get the abbreviated month name (e.g.

"Jan").

int Date::getSundayWeekOfYear  
 

Get the week of the year for weeks starting on Sunday.

int Date::getSundayWeeksInYear year_t    year [static]
 

Get the number of weeks in a year (for weeks starting on Sunday).

weekday_t Date::getWeekday   const [inline]
 

Get the day of the week as an integer (1=MONDAY..7=SUNDAY).

const char * Date::getWeekdayName  
 

Get the full day of the week name (e.g.

"Monday").

const char * Date::getWeekdayShortName  
 

Get the abbreviated day of the week name (e.g.

"Mon").

int Date::getWeeksInYear year_t    year [static]
 

Get the number of weeks in a year (for weeks starting on Monday).

year_t Date::getYear   const [inline]
 

Get the year.

bool Date::isFirstOfMonth   const [inline]
 

Returns true if it is the first day of the month (i.e.

day == 1).

bool Date::isLastOfMonth   const [inline]
 

Returns true if it is the last day of the month.

bool Date::isLeap year_t    year [inline, static]
 

Returns true if the year is a leap year.

bool Date::isLeap   const [inline]
 

Returns true if this is a leap year.

const Date& Date::operator= const Date &    d [inline]
 

Assignment.

void Date::setJulian julian_t    j [inline]
 

Set the Julian day.

void Date::subtractDays int    ndays [inline]
 

Subtract a number of days from the date.

void Date::subtractMonths int    nmonths
 

Subtract a number of months to the date.

The day will be truncated to fit within the new month.

void Date::subtractYears int    nyears
 

Subtract a number of years to the date.

February 29 change to February 28 for non-leap years.

virtual std::string Date::typeString   const [inline, virtual]
 

Return a string representation of the type.

Reimplemented in DateZulu, and SimDate.

bool Date::validYMD year_t    year,
month_t    month,
day_t    day
[inline, static]
 

Check if a given (year, month, day) exists.


The documentation for this class was generated from the following files:
SimData version pre-0.4.0. For more information on SimData, visit the SimData Homepage.

Generated on Tue Oct 14 12:06:40 2003, using Doxygen 1.2.18.

[SF.net]