Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

look::LookDate Class Reference

Date. More...

#include <lkdatetime.h>

Inheritance diagram for look::LookDate::

look::LookTypeBase List of all members.

Public Methods

 LookDate (unsigned long julianDate=0UL)
 Constructor. More...

 LookDate (const LookDate &theOther)
 Copy constructor.

 LookDate (unsigned int theDay, unsigned int theMonth, unsigned int theYear)
 Constructor. More...

 LookDate (unsigned int theDay, const LookString &theMonth, unsigned int theYear)
 Constructor. More...

 ~LookDate (void)
 Destructor.

LookTypeBaseGetNewCopy (void) const
 Get a new copy. More...

long GetTypeID (void) const
 Get Type ID. More...

LookDate& operator++ ()
 Prefix ++. Add one day.

LookDate operator++ (int)
 Postfix ++. Add one day.

LookDate& operator-- ()
 Prefix --. Subtract one day.

LookDate operator-- (int)
 Postfix --. Subtract one day.

LookDate& operator+= (long theDays)
 Add days to self. More...

LookDate operator+ (long theDays) const
 Add days. More...

LookDate& operator-= (long theDays)
 Subtract days from self. More...

LookDate operator- (long theDays) const
 Subtract days from self. More...

long operator- (const LookDate &theDate) const
 Days between two dates. More...

void AddMonths (int theMonths)
 Add Months.

bool operator== (const LookDate &theOther) const
 Equal.

bool operator!= (const LookDate &theOther) const
 Not equal.

bool operator< (const LookDate &theOther) const
 Less than.

bool operator> (const LookDate &theOther) const
 Greater than.

bool operator<= (const LookDate &theOther) const
 Less than or equal.

bool operator>= (const LookDate &theOther) const
 Greater than or equal.

bool IsSet (void) const
 Is the date set? More...

unsigned int DayOfMonth (void) const
 Day of the month (1-31).

unsigned int Month (void) const
 Month of the year(1-12, 1 = January).

unsigned int Year (void) const
 Year.

unsigned int DayOfYear (void) const
 Day in year (1-366).

unsigned int DayOfWeek (void) const
 Day in week (1-7, 1 = Monday).

LookString DayName (void) const
 Day as string ("Monday").

LookString MonthName (void) const
 Month as string ("March").

LookDate Previous (unsigned int dayNumber) const
 Previous monday, tuesday, etc. More...

LookDate Next (unsigned int dayNumber) const
 Next monday, tuesday, etc. More...

bool IsLeap (void) const
 Are we a leap year?

bool Set (LookString theDateString)
 Set from a string. More...

LookString GetString (const LookString &theSeparator="/", const LookString &theOrder="dmy", bool monthIsNumber=true, int yearDigits=4) const
 Get as a string. More...


Static Public Methods

LookDate Now (void)
 Today according to localtime().

unsigned int DayFromName (LookString theDayName)
 Convert a weekday from a name to a number. More...

LookString NameFromDay (unsigned int theDayNumber)
 Convert a weekday from a number to a name. More...

LookString ShortNameFromDay (unsigned int theDayNumber)
 Convert a weekday from a number to a short name. More...

unsigned int MonthFromName (LookString theMonthName)
 Convert a month from a name to a number. More...

LookString NameFromMonth (unsigned int theMonthNumber)
 Convert a month number to a month name. More...

LookString ShortNameFromMonth (unsigned int theMonthNumber)
 Convert a month number to a short month name. More...

unsigned int DaysInMonth (unsigned int theMonthNumber, unsigned int theYear)
 How many days are in a month/year. More...

bool IsLeap (unsigned int theYear)
 Is theYear a leap year?

void ConvertFromJulian (unsigned long theJulianDate, unsigned int &year, unsigned int &month, unsigned int &day)
 Convert from a julian date to day/month/year. More...

unsigned long ConvertToJulian (unsigned int year, unsigned int month, unsigned int day)
 Convert day/month/year to a julian date. More...

void SetCenturyBoundary (int theBoundary)
 Set century boundary. See LookDate::itsCenturyBoundary.

int GetCenturyBoundary (void)
 Get century boundary. See LookDate::itsCenturyBoundary.


Protected Attributes

unsigned long itsJulianDate
 Julian date.


Static Protected Attributes

unsigned int itsCenturyBoundary
 Century conversion boundary. More...


Detailed Description

Date.

This class represents a date.

It stores its value as a julian date, ie the number of days since one day a very long time ago. (a standard one though...)

This version doesn't handle anything but the gregorian calendar, so don't use it for dates < Sep. 14, 1752.

The conversions to and from strings are English-only at the moment.


Constructor & Destructor Documentation

look::LookDate::LookDate ( unsigned long julianDate = 0UL )
 

Constructor.

The default value of 0 will make IsSet() return false.

look::LookDate::LookDate ( unsigned int theDay,
unsigned int theMonth,
unsigned int theYear )
 

Constructor.

theDay is 1-31, theMonth 1-12, theYear the full 4-digit year. If any combination of these is invalid, itsJulianDate will be set to 0 and IsSet() will return false.

look::LookDate::LookDate ( unsigned int theDay,
const LookString & theMonth,
unsigned int theYear )
 

Constructor.

theDay is 1-31, theMonth either the full month name or the 3-letter abbreviation, theYear the full 4-digit year. theMonth is case-insensitive. If any combination of these is invalid, itsJulianDate will be set to 0 and IsSet() will return false.


Member Function Documentation

void look::LookDate::ConvertFromJulian ( unsigned long theJulianDate,
unsigned int & year,
unsigned int & month,
unsigned int & day ) [static]
 

Convert from a julian date to day/month/year.

Parameters:
theJulianDate   Julian Date
year   The year will be returned in here
month   The month will be returned in here
day   The day will be returned in here

unsigned long look::LookDate::ConvertToJulian ( unsigned int year,
unsigned int month,
unsigned int day ) [static]
 

Convert day/month/year to a julian date.

If day/month/year is not a valid date, then the return will be 0.

Parameters:
year   Year (not 2-digit appreviation)
month   Month (1-12)
day   Day of month (1-31)
Returns:
Julian date.

unsigned int look::LookDate::DayFromName ( LookString theDayName ) [static]
 

Convert a weekday from a name to a number.

Monday = 1, Sunday = 7.

Parameters:
theDayName   The name. Either a full name or a 3-letter abbreviation. Case-insensitive.
Returns:
the day number

unsigned int look::LookDate::DaysInMonth ( unsigned int theMonthNumber,
unsigned int theYear ) [static]
 

How many days are in a month/year.

Obviously you need to give the year to account for leap years.

Parameters:
theMonthNumber   The month number - must be 1-12.
theYear   The year.
Returns:
Number of days in that month.

LookTypeBase * look::LookDate::GetNewCopy ( void ) const [virtual]
 

Get a new copy.

Virtual copy constructor, aka clone.

Returns:
A new copy of this. (You are responsible for deleting it).

Reimplemented from look::LookTypeBase.

LookString look::LookDate::GetString ( const LookString & theSeparator = "/",
const LookString & theOrder = "dmy",
bool monthIsNumber = true,
int yearDigits = 4 ) const
 

Get as a string.

The D, M and Y characters of theOrder are considered (case-insensitive).

The return string is build up with d's replaced by the day of the month, m's by the month string and y's by the year string. theSeparator is placed between all of these.

Eg GetString( "/", "dmy", true, 4) will give "25/02/1993" and GetString( "-", "mdy", false, 2) will give "Feb-25-93"

LookDateTimeFormatter is a much more general formatter, but not as efficient.

Parameters:
theSeparator   The string between the d, m and y portions.
theOrder   Order string. This should only consist of the letters d, m and y (or D, M and Y)
monthIsNumber   If true, the month string will be 1-12, otherwise it will be the three-letter abbreviation.
yearDigits   How many digits the year will be converted to. Eg 1978 will be converted to 8, 78, 978, 1978, 01978 with yearDigits of 1-5 respectively.
Returns:
The string.

long look::LookDate::GetTypeID ( void ) const [virtual]
 

Get Type ID.

Pseudo-rtti, or isA.

Returns:
LookDateID

Reimplemented from look::LookTypeBase.

bool look::LookDate::IsSet ( void ) const
 

Is the date set?

Note adding 1 to an unset date results in a set date (although a very long time ago).

Returns:
false if itsJulianDate is 0, true otherwise

unsigned int look::LookDate::MonthFromName ( LookString theMonthName ) [static]
 

Convert a month from a name to a number.

January = 1, December = 12.

Parameters:
theMonthName   The name. Either a full name or a 3-letter abbreviation. Case-insensitive.
Returns:
the day number

LookString look::LookDate::NameFromDay ( unsigned int theDayNumber ) [static]
 

Convert a weekday from a number to a name.

Monday = 1, Sunday = 7.

Parameters:
theDayNumber   The day number - must be 1-7
Returns:
the day name eg "Monday".

LookString look::LookDate::NameFromMonth ( unsigned int theMonthNumber ) [static]
 

Convert a month number to a month name.

January = 1, December = 12.

Parameters:
theMonthNumber   The month number - must be 1-12
Returns:
the month name eg "March".

LookDate look::LookDate::Next ( unsigned int dayNumber ) const
 

Next monday, tuesday, etc.

Like Previous(), only the next date.

Parameters:
dayNumber   The day of the week (1-7, monday = 1)
Returns:
Next date

LookDate look::LookDate::Previous ( unsigned int dayNumber ) const
 

Previous monday, tuesday, etc.

Easiest described with an example - dayNumber = 3, Wednesday. If this date is a Tuesday, it returns the date 6 days before. If this date is a Wednesday, it retuns the date 7 days before. If this date is a Thursday, it retuns the date 1 day before.

All of these are the previous Wednesday.

Parameters:
dayNumber   The day of the week (1-7, monday = 1)
Returns:
Previous date

bool look::LookDate::Set ( LookString theDateString )
 

Set from a string.

This can cope with a variety of formats. See LookDateTimeReader for a more general converter.

The formats are:

  • dd-mon-yyyy
  • dd/mm/yy
  • yymmdd
  • yyyy-mm-dd
  • dd.mm.yyyy
  • yyyy-mon-dd
  • mon-dd-yyyy
  • dd/mm/yyyy
Where dd is day of month, mm is month of year (number), mon is month of year (3 letter abbreviation) and yy and yyyy are years. mon is case-insensitive.

If it is a two-digit year, it is converted to a four-digit year in 1900-2099 using itsCenturyBoundary.

Only that portion of theDateString up to the first space is considered.

Parameters:
theDateString   The date string.
Returns:
true for success, false otherwise.

LookString look::LookDate::ShortNameFromDay ( unsigned int theDayNumber ) [static]
 

Convert a weekday from a number to a short name.

Monday = 1, Sunday = 7.

Parameters:
theDayNumber   The day number - must be 1-7
Returns:
the day name eg "Mon".

LookString look::LookDate::ShortNameFromMonth ( unsigned int theMonthNumber ) [static]
 

Convert a month number to a short month name.

January = 1, December = 12.

Parameters:
theMonthNumber   The month number - must be 1-12
Returns:
the month name eg "Mar".

LookDate look::LookDate::operator+ ( long theDays ) const
 

Add days.

Parameters:
theDays   Number of days to add
Returns:
*this + theDays.

LookDate & look::LookDate::operator+= ( long theDays )
 

Add days to self.

Parameters:
theDays   Number of days to add
Returns:
*this.

long look::LookDate::operator- ( const LookDate & theDate ) const
 

Days between two dates.

The difference (in days) between self and theOther. If theOther is before self, the return will be negative.

Parameters:
theOther   Other date.
Returns:
Number of days between.

LookDate look::LookDate::operator- ( long theDays ) const
 

Subtract days from self.

Parameters:
theDays   Number of days to subtract.
Returns:
*this - theDays.

LookDate & look::LookDate::operator-= ( long theDays )
 

Subtract days from self.

Parameters:
theDays   Number of days to subtract.
Returns:
*this.


Member Data Documentation

unsigned int look::LookDate::itsCenturyBoundary [static, protected]
 

Century conversion boundary.

For converting two-digit years to four-digit - the Y2K problem.

If boundary is 10, 11 is converted to 1911 and 10 to 2010


The documentation for this class was generated from the following files:
Generated at Thu Jan 17 12:53:08 2002 for liblookdb by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001