DTime+, A collection of Date and Time Classes for C++/MFC

Version 3.09

Copyright (c) 1995 - 2007 PJ Naughter

 

DTime+ is a collection of classes & functions designed to ease the MFC programmers’ burden when handling date and time values. If like me, having taken a look at the built in MFC classes CTime and CTimeSpan or the OLE based COleDateTime and COleDateTimeSpan classes, you decided they did not meet your requirements, and you decided to write your own super-duper date and time classes, but deadlines were looming, then look no further. The basis of the algorithms for conversion from the Julian and Gregorian calendar to the underlying storage was adopted from an article by Peter J.G. Meyer for the March 1993 issue of Dr Dobbs Journal. You can find the article online at http://www.ddj.com/184408959. The algorithm used to determine the date of Easter Sunday is taken from the book ‘Astronomical Algorithms’ by Jean Meeus. The algorithms for the Moslem (Islamic) and Hebrew calendar are provided by the book "Calendrical Calculations, The Millenium Edition" by Edward M. Reingold and Nachum Dershowitz. Calendrical Calculations has always been a favourite topic of the author and was in fact some of the first code which I published on the web back in the mid 90's. Originally the code was shareware but I've now decided to make it freeware in the hope that more people will find it useful in their day to day projects.

 

 

 

Sections in this Document

Copyright

Features

History

How to Use

CDate Index

CLTimeSpan Index

CLTimeOfDay Index

CLDate Index

Structures used by the classes

Future Enhancements

UI Support

Contacting the Author

 

 

 

Copyright

 

 

 

Features

 

 

 

History

v1.0 v1.1 v1.11 v2.0 v2.1

v2.2

v2.21 (17 July 1998)

v2.22 (14 May 1999) 11 April 2000

v3.0 (22 April 2006)

v3.01 (1 May 2006)

v3.02 (20 May 2006)

v3.03 (22 May 2006)

v3.04 (25 May 2006)

v3.05 (27 May 2006)

v3.06 (29 May 2006)

v3.07 (30 May 2006)

v3.08 (2 July 2006)

v3.09 (13 April 2007)

 

 

 

How to use

As DTime+ is provided as a C++ template class library, you simple need to #include the relevant header files (e.g. DTime+.h) in your project. You can also reference individual DTime+ headers also if you want. For example if you want to use the UI support for DTime+, you can include DTime+UI.h.

 

 

 

CDate Index

Construction

CDate

Setting

Set

Static Constructors

CurrentSystemDate

CurrentLocalDate

JDEpoch

MJDEpoch

Epoch1900

Epoch1950

EpochCTime

Epoch2000

GregorianEpoch

Static Operations

IsLeap

DaysInYear

DaysInMonth

DaysSinceFirstOfYear

DaysSinceEndPreviousYear

GetBeginingDayOfWeek

GetFullStringDayOfWeek

GetAbrStringDayOfWeek

GetFullStringMonth

GetAbrStringMonth

Operations

DaysSinceFirstOfYear

DaysSinceEndPreviousYear

GetDate

GetDay

GetMonth

GetYear

GetCEBCEYear

Get2DigitYear

GDN

JD

IsLeap

DaysInYear

DaysInMonth

AddYear

AddMonth

AddWeek

GetDayOfWeek

GetFullStringDayOfWeek

GetAbrStringDayOfWeek

GetFullStringMonth

GetAbrStringMonth

GetAsSystemTime

GetAsFileTime

GetAsTM

GetWeekOfYear

GetWeekOfMonth

IsValid

Collate

Construction based on this instance

FirstThisMonth

LastThisMonth

FirstThisYear

LastThisYear

Overloaded Arithmetic Operators

operator=

operator+,-

operator+=, -=

operator++

operator--

operator==, <, etc.

Display

GetWindowsFormatString

Format

Serialization

Serialize

operator<<

operator>>

 

 

CDate::CDate

CDate();

CDate(long Year, WORD month, WORD Day, bool bDoAssert = true);

CDate(const SYSTEMTIME& SystemTime, bool bDoAssert = true);

CDate(const FILETIME& FileTime, bool bDoAssert = true);

CDate(long Year, WORD month, WORD WeekOfMonth, DayOfWeek dow, bool bDoAssert = true);

CDate(long Days, DateEpoch e, bool bDoAssert = true);

CDate(const CDate& d);

CDate(const CTime& ctime, bool bDoAssert = true);

CDate(const COleDateTime& oleTime);

CDate(const CString& sDate, const CString& sFormat, bool bDoAssert = true);

Parameters

Year, Month, Day Indicates a year, month and day.

SystemTime A Win32 SDK SYSTEMTIME struct.

FileTime A Win32 SDK FILETIME struct.

d Indicates a CDate object that already exists.

ctime Indicates a CTime object that already exists.   

WeekOfMonth The week of the month (1 - 5).

DayOfWeek The day of the week e.g. Sunday.

oleTime An OLE Date.

sDate A string representation of the date to construct

sFormat The format that the string date uses

bDoAsserts If set, the constructors will assert in debug mode if any of the parameters are invalid

Remarks

sFormat                    sDate                       Result
‘dmy2/’                    ‘20/03/96’               20th March 1996
‘mdy4-’                     ‘03-28-1996’            28th March 1996

This feature allows for the creation of CDate's from a string as entered in a masked edit field or from a parsed report.

 

CDate::Set

CDate& Set();

CDate& Set(long Year, WORD month, WORD Day, bool bDoAssert = true);

CDate& Set(const SYSTEMTIME& SystemTime, bool bDoAssert = true);

CDate& Set(const FILETIME& FileTime, bool bDoAssert = true);

CDate& Set(long Year, WORD month, WORD WeekOfMonth, DayOfWeek dow, bool bDoAssert = true);

CDate& Set(long Days, CDate::DateEpoch e, bool bDoAssert = true);

CDate& Set(const CTime& ctime, bool bDoAssert = true);

CDate& Set(const COleDateTime& oleTime);

CDate& Set(const CString& sDate, const CString& sFormat, bool bDoAssert = true);

Parameters

See CDate Constructors

Remarks

 

static CDate::CurrentSystemDate(bool bDoAssert = true);

Returns a CDate which represents the current UTC date as taken from the system clock.

 

static CDate::CurrentLocalDate(bool bDoAssert = true);

Returns a CDate which represents the current local date as taken from the system clock.

 

static CDate CDate::JDEpoch();

Returns a CDate which represents Julian Day Epoch i.e. 1st January -4712 (when specified in the Julian calendar)

 

static CDate CDate::MJDEpoch();

Returns a CDate which represents 1st January -4712 + 2400000 Days (which corresponds to 17 November 1858 in the Gregorian calendar)

 

static CDate CDate::Epoch1900();

Returns a CDate which represents 1st January 1900

 

static CDate CDate::Epoch1950();

Returns a CDate which represents 1st January 1950

 

static CDate CDate::EpochCTime();

Returns a CDate which represents a CTime of 0 seconds (i.e. 1st January 1970)

 

static CDate CDate::Epoch2000();

Returns a CDate which represents 1st January 2000

 

static CDate CDate::GregorianEpoch();

Returns a CDate which represents when the change from the Julian to Gregorian calendar occurred.

 

static bool CDate::IsLeap(long Year);

returns true if the year is leap otherwise false.

Remarks

The routine correctly allows for the exception whereby dates in the Gregorian calendar are leap (or bissextile) if divisible by 4 with the following exception: the centurial years that are not divisible by 400, such as 1700, 1800, 1900, and 2100, are not leap years. The other century years, which are divisible by 400, are leap years, for instance 1600, 2000 and 2400. If we have instantiated for the Julian Calendars, then the simpler 4 year leap year rule is applied. If we have instantiated the CDate for the Moslem or Hebrew calendars, then their specific leap year / leap month rules will be applied.

 

static WORD CDate::DaysInYear(long Year);

Returns the number of days in a year i.e. 366 if the year is leap otherwise 365, assuming we have instantiated the CDate class using the Gregorian or Julian Calendars. If instantiated for the Moslem or Hebrew calendars, then their specific leap year / leap month rules will be applied. In the Moslem calendar, a year can contain 354 or 355 days. In the Hebrew calendar, a year can contain 353, 354, 355, 383, 384 or 385 days.

 

static WORD CDate::DaysInMonth(long Year, WORD month);

Returns the number of days in a month e.g. 31 for January, 28 for a common February, 29 for a leap February etc, assuming we have instantiated the CDate class using the Gregorian or Julian Calendars. If instantiated for the Moslem or Hebrew calendars, then their specific leap year / leap month rules will be applied.

 

static WORD CDate::DaysSinceFirstOfYear(long Year, WORD month, WORD Day);

Returns the number of days since 1st of January. If the CDate class has been instantiated using the Moslem calendar, then the first of the year will correspond to the 1st day of the Moslem month Muharram. If the CDate class has been instantiated using the Hebrew calendar, then it returns the number of days since 1st day of Tishri. Note this function does not return the number of days since 1st of Nisan which is the 1st month in the Hebrew calendar because Hebrew New Year is 1st of Tishri which is the 7th month.

 

static WORD CDate::DaysSinceEndPreviousYear(long Year, WORD month, WORD Day);

Returns the number of days since 0th of January (previous 31st December). If the CDate class has been instantiated using the Moslem calendar, then the end of the previous year will correspond to the 29th or 30th of the Moslem month Dhu al-Hijja. If the CDate class has been instantiated using the Hebrew calendar, then it returns the number of days since 0th of Tishri (previous 29th of Elul). Note this function does not return the number of days since the last day of Adar I or Adar II (if it is a leap year) because Hebrew New Year is 1st of Tishri which is the 7th month.

 

static CString CDate::GetFullStringDayOfWeek(DayOfWeek dow, LCID Locale = LOCALE_USER_DEFAULT);

Returns a representation of the day of week parameter as a CString, returning for example ‘Sunday’, ‘Monday’ etc assuming the locale specified is for an English language and you have constructed the CDate instance using the Julian or Gregorian calendar.

Remarks

See Also

CDate::GetAbrStringDayOfWeek

 

static CString CDate::GetAbrStringDayOfWeek(DayOfWeek dow, LCID Locale = LOCALE_USER_DEFAULT);

Returns an abbreviated representation for the day of week parameter as a CString, returning for example ‘Sun’, ‘Mon’ etc assuming the locale specified is for an English language and you have constructed the CDate instance using the Julian or Gregorian calendar.

Remarks

See Also

CDate::GetFullStringDayOfWeek

 

static CString CDate::GetFullStringMonth(WORD month, LCID Locale = LOCALE_USER_DEFAULT);

Returns a CString representation for the month parameter, returning for example ‘January’, ‘February’ etc assuming the locale specified is for an English language and you have constructed the CDate instance using the Julian or Gregorian calendar.

See Also

CDate::GetAbrStringMonth

 

static CString CDate::GetAbrStringMonth(WORD month, LCID Locale = LOCALE_USER_DEFAULT);

Returns a CString representation for the month parameter, returning for example ‘Jan’, ‘Feb’ etc assuming the locale specified is for an English language and you have constructed the CDate instance using the Julian or Gregorian calendar.

See Also

CDate::GetFullStringMonth

 

WORD CDate::DaysSinceFirstOfYear() const;

Returns the number of days since 1st of January for this instance. If the CDate class has been instantiated using the Moslem calendar, then the first of the year will correspond to the 1st day of the Moslem month Muharram.

 

WORD CDate::DaysSinceEndPreviousYear() const;

Returns the number of days since 0th of January (previous 31st December) for this instance. If the CDate class has been instantiated using the Moslem calendar, then the end of the previous year will correspond to 29th or 30th of the Moslem month Dhu al-Hijja.

 

static WORD CDate::GetBeginingDayOfWeek(LCID Locale = LOCALE_USER_DEFAULT);

Gets the day of week considered to be the beginning day of week for the specified locale. It uses this value in CDate::GetWeekOfYear() and CDate::GetWeekOfMonth()

Remarks

 

CDate::DateS CDate::GetDate() const;

Returns a DateS structure for this instance.

 

WORD CDate::GetDay() const;

Returns the Day of the month for this instance (1 - 31).

 

WORD CDate::GetMonth() const;

Returns the Month enum for this instance (January(1) - December (12)).

 

long CDate::GetYear() const;

Returns the Year for this instance.

 

long CDate::GetCEBCEYear(bool& IsCE) const;

Returns the Current Epoch / Before Current Epoch year for this instance.

e.g.

bool bIsCE;

CDate<CGregorianCalendar> x(1990, January, 32);

long y = x.GetCEBCEYear(bIsCE);        //y will be 1990, bIsCE will be true

x.Set(-1990, January, 32);

y = x.GetCEBCEYear(bIsCE);                   //y will be 1989, bIsCE will be false

 

long CDate::Get2DigitYear() const;

Returns the last 2 digits of the year.

e.g.

CDate<CGregorianCalendar> x(1995, January, 15);

long y = x.Get2DigitYear();

ASSERT(y == 95);

 

long CDate::GDN() const;

Returns the number of days for this instance since the Gregorian Epoch.

 

long CDate::JD() const;

Returns the Julian Day or number of days for this instance since 1st January -4712.

 

bool CDate::IsLeap() const;

Returns true if the year for this instance is leap otherwise false.

 

WORD CDate::DaysInYear() const;

Returns the number of days for this instance’s year.

 

WORD CDate::DaysInMonth() const;

Returns the number of days for this instance’s month.

 

void CDate::AddYear(int Years = 1);

Adds a number of years to this instance.

 

void CDate::AddMonth(int Months = 1);

Adds a number of months to this instance.

Remarks

 

void CDate::AddWeek(int Weeks = 1);

Adds a number of weeks i.e. 7 days to this instance.

 

WORD CDate::GetDayOfWeek() const;

Returns the day of week for this instance. (1 for Sunday, 2 for Monday, and so forth).

Remarks

 

CString CDate::GetFullStringDayOfWeek(LCID Locale = LOCALE_USER_DEFAULT) const;

Returns the day of week for this instance as a CString. e.g. 'Sunday', 'Monday' etc  assuming the locale specified is for an English language and you have constructed a Julian or Gregorian CDate instance.

See Also

CDate::GetAbrStringDayOfWeek

 

CString CDate::GetAbrStringDayOfWeek(LCID Locale = LOCALE_USER_DEFAULT) const;

Returns an abbreviated CString version for the day of week for this instance. e.g. ‘Sun’, ‘Mon’ etc assuming the locale specified is for an English language and you have constructed a Julian or Gregorian CDate instance.

See Also

CDate::GetFullStringDayOfWeek

 

CString CDate::GetFullStringMonth(LCID Locale = LOCALE_USER_DEFAULT) const;

Returns the full CString version for the month for this instance. e.g. ‘January’, ‘February’ etc assuming the locale specified is for an English language and you have constructed a Julian or Gregorian CDate instance.

See Also

CDate::GetAbrStringMonth

 

CString CDate::GetAbrStringMonth(LCID Locale = LOCALE_USER_DEFAULT) const;

Returns an abbreviated CString version for the month for this instance. e.g. ‘Jan’, ‘Feb’ etc assuming the locale specified is for an English language and you have constructed a Julian or Gregorian CDate instance.

See Also

CDate::GetFullStringMonth

 

bool CDate::GetAsSystemTime(SYSTEMTIME& SystemTime) const;

Returns a Win32 SDK SYSTEMTIME struct version of this instance.

Remarks

 

bool CDate::GetAsFileTime(FILETIME& FileTime) const;

Returns a Win32 SDK FILETIME struct version of this instance.

Remarks

 

bool CDate::GetAsTM(tm& time) const;

Returns a ‘C’ runtime tm struct version of this instance.

 

WORD CDate::GetWeekOfYear(LCID Locale = LOCALE_USER_DEFAULT) const;

Returns the week of the year for this instance. As an example of how this is determined:

Suppose the 1st of January occurred on a Thursday and the day of week considered the beginning of the week is Monday as specified by the locale value 'Locale'. The following results would then be obtained:

Date                        GetWeekOfYear() return value

Thursday 1st            0

Friday 2nd                0

Saturday 3rd            0

Sunday 4th              0

Monday 5th             1

Tuesday 6th            1

.

.

Monday 12th           2

.

.

.

 

WORD CDate::GetWeekOfMonth(LCID Locale = LOCALE_USER_DEFAULT) const;

Returns the week of the month for this instance. As an example of how this is determined:

Suppose the 1st of the month occurred on a Thursday and the day of week considered the beginning of the week is Monday as specified by the locale value 'Locale', The following results would then be obtained:

Date                        GetWeekOfMonth() return value

Thursday 1st            0

Friday 2nd                0

Saturday 3rd            0

Sunday 4th              0

Monday 5th             1

Tuesday 6th            1

.

.

Monday 12th           2

.

.

.

 

bool CDate::IsValid() const;

Returns true if this instance is valid otherwise false.

e.g. CDate<CGregorianCalendar> Inval(1990, January, 33, false); //an invalid day of month

ASSERT(IsValid(Inval) == false);

 

long CDate::Collate() const;

Returns a long which can be used in a date collation purposes i.e. the year value is stored as units of 10000, the month value is stored as units of 100 and the day value as units of 1.

e.g. CDate<CGregorianCalenda> x(1978, March, 3);

ASSERT(x.Collate = 19780403L);

 

CDate CDate::FirstThisMonth();

Returns a CDate for the first of the month for this instance

e.g. CDate<CGregorianCalendar> x(1990, March, 4);

CDate<CGregorianCalendar> f(x.FirstThisMonth());

ASSERT(f = CDate<CGregorianCalendar>(1990, March, 1);

See Also

CDate::LastThisMonth

 

CDate CDate::LastThisMonth();

Returns a CDate for the last of the month for this instance

e.g. CDate<CGregorianCalendar> x(1990, March, 4);

CDate<CGregorianCalendar> f(x.LastThisMonth());

ASSERT(f = CDate<CGregorianCalendar>(1990, CDate::March, 31);

See Also

CDate::FirstThisMonth

 

CDate CDate::FirstThisYear();

Returns a CDate for the 1st January for this instance

e.g. CDate<CGregorianCalendar> x(1990, March, 4);

CDate<CGregorianCalendar> f(x.FirstThisYear());

ASSERT(f = CDate<CGregorianCalendar>(1990, January, 1);

See Also

CDate::LastThisYear

 

CDate CDate::LastThisYear();

Returns a CDate for the 31st December for this instance

e.g. CDate<CGregorianCalendar> x(1990, March, 4);

CDate<CGregorianCalendar> f(x.LastThisYear());

ASSERT(f = CDate<CGregorianCalendar>(1990, December, 31);

See Also

CDate::FirstThisYear

 

CDate& CDate::operator=(const CDate& d);

Copies a CDate into this CDate and returns a reference to this instance

 

CDate CDate::operator+(long Days) const;

CDate CDate::operator-(long Days) const;

Standard arithmetic operators to add and subtracts a number of days.

e.g. CDate<CGregorianCalendar> Tomorrow(CDate<CGregorianCalendar>::CurrentLocalDate()) + 1;

long OneMonth = CDate<CGregorianCalendar>(1990, March, 4) - CDate<CGregorianCalendar>(1990, February, 4);

CDate<CGregorianCalendar> Yesterday(CDate<CGregorianCalendar>::GetLocalDate()) - 1;

 

CDate& CDate::operator+=(long Days);

CDate& CDate::operator-=(long Days);

Standard arithmetic increment and decrement operators

e.g. CDate<CGregorianCalendar> x(1990, January, 1);

x += 7;

ASSERT(x == CDate<CGregorianCalendar>(1990, January, 8));

x -= 7;

ASSERT(x == CDate<CGregorianCalendar>(1990, January, 1));

 

CDate& CDate::operator++();

Standard arithmetic increment operator. Adds one day to this instance

 

CDate& CDate::operator--();

Standard arithmetic decrement operator. Subtracts one day from this instance.

 

bool CDate::operator==(const CDate& d) const;

bool CDate::operator>(const CDate& d) const;

bool CDate::operator>=(const CDate& d) const;

bool CDate operator<(const CDate& d) const;

bool CDate operator<=(const CDate& d) const;

bool CDate operator!=(const CDate& d) const;

Standard arithmetic equality operators.

 

CString CDate::GetWindowsFormatString(LCID Locale = LOCALE_USER_DEFAULT)

Returns a CDate::Format string appropriate for the specified windows locale as specified by 'Locale'

See Also

CDate::Format

 

CString CDate::Format(const CString& sFormat = GetWindowsFormatString(LOCALE_USER_DEFAULT), LCID Locale = LOCALE_USER_DEFAULT) const;

Generates a formatted string that corresponds to this CDate object.

The sFormat string supports the following replaceable parameters:

Remarks

See Also

CDate::GetWindowsFormatString

 

void CDate::Serialize(CArchive& ar);

Standard MFC override to allow streaming of this CDate to and from an archive. The space taken is 6 bytes (4 data bytes + 2 schema bytes).

Remarks

As of v3 of DTime+, the serialization is not backward compatible with earlier versions.

 

friend CArchive& operator<<(CArchive& ar, CDate& Date);

Simply calls the Serialize method of ‘Date’, asserting that the archive ‘ar’ is storing.

 

friend CArchive& operator>>(CArchive& ar, CDate& Date);

Simply calls the Serialize method of ‘Date’, asserting that the archive ‘ar’ is loading.

 

 

 

CLTimeSpan Index

Construction

CLTimeSpan

Setting

Set

Static Constructors

OneDay

OneHour

OneMinute

OneSecond

Operations

GetTotalDays

GetHours

GetMinutes

GetSeconds

IsValid

Negate

IsPositiveSpan

SecondsAsDouble

Overloaded Arithmetic Operators

operator=

operator+,-

operator+=.-=

operator*, /

operator*=, /=

Overloaded Equality Operators

operator==, > etc.

Display

GetWindowsFormatString

Format

Serialization

Serialize

operator<<

operator>>

 

CLTimeSpan Constructors

CLTimeSpan();

CLTimeSpan(long Day, WORD Hour, WORD Minute, WORD Second);

CLTimeSpan(const CLTimeSpan& lts);

CLTimeSpan(const CTimeSpan& ts);

CLTimeSpan(const CLTimeOfDay& tod);

CLTimeSpan(const COleDateTimeSpan& oleTimeSpan);

CLTimeSpan(const __int64& Seconds);

Parameters

Day, Hour, Minute, Second Indicates a count of day, hour, minute and second values.

lts Indicates a CLTimeSpan object that already exists.

ts Indicates a CTimeSpan object that already exists.

tod Indicates a CLTimeOfDay object that already exists.

Seconds Indicates a count of seconds as a 64 bit integer.

oleTime An OLE time span.

Remarks

 

CLTimeSpan Set functions

CLTimeSpan& Set();

CLTimeSpan& Set(long Day, WORD Hour, WORD Minute, WORD Second);

CLTimeSpan& Set(const CTimeSpan& ts);

CLTimeSpan& Set(const CLTimeOfDay& tod);

CLTimeSpan& Set(const COleDateTimeSpan& oleTimeSpan);

CLTimeSpan& Set(const __int64& Seconds);

Parameters

See CLTimeSpan Constructors

Remarks

 

static CLTimeSpan CLTimeSpan::OneDay();

Returns a CLTimeSpan which represents one day.

 

static CLTimeSpan CLTimeSpan::OneHour();

Returns a CLTimeSpan that represents one hour.

 

static CLTimeSpan CLTimeSpan::OneMinute();

Returns a CLTimeSpan that represents one minute.

 

static CLTimeSpan CLTimeSpan::OneSecond();

Returns a CLTimeSpan that represents one second.

 

long CLTimeSpan::GetTotalDays() const;

Returns the total number of days this CLTimeSpan contains.

e.g. CLTimeSpan x(10, 12 , 13, 14)

ASSERT(x.GetTotalDays() == 10);

 

WORD CLTimeSpan::GetHours() const;

Returns the number of hours this CLTimeSpan contains.

e.g. CLTimeSpan x(10, 12 , 13, 14)

ASSERT(x.GetHours() == 12);

 

WORD CLTimeSpan::GetMinutes() const;

Returns the number of minutes this CLTimeSpan contains.

e.g. CLTimeSpan x(10, 12 , 13, 14)

ASSERT(x.GetMinutes() == 13);

 

WORD CLTimeSpan::GetSeconds() const;

Returns the number of seconds this CLTimeSpan contains.

e.g. CLTimeSpan x(10, 12 , 13, 14)

ASSERT(x.GetSeconds() == 14);

 

bool CLTimeSpan::IsValid() const;

Returns true if this instance is valid otherwise false.

e.g. CLTimeSpan Inval;

ASSERT(IsValid(Inval) == false);

 

CLTimeSpan& CLTimeSpan::Negate();

Negates this CLTimeSpan and returns a reference to it.

e.g. CLTimeSpan x(10, 12 , 13, 14)

x.Negate();

ASSERT(x == CLTimeSpan(-10, 12, 13, 14);

 

bool CLTimeSpan::IsPositiveSpan() const;

Returns true if this CLTimeSpan represents a positive time span (value >= 0 seconds) else negative.

e.g. CLTimeSpan x(-10, 12 , 13, 14)

ASSERT(!x.IsPositiveSpan());

 

double CLTimeSpan::SecondsAsDouble() const;

Returns the underlying number of seconds this CLTimeSpan contains as a double.

 

CLTimeSpan& CLTimeSpan::operator=(const CLTimeSpan& TimeSpan)

Copies a CLTimeSpan into this CLTimeSpan and returns a reference to this instance

 

CLTimeSpan CLTimeSpan::operator+(const CLTimeSpan& TimeSpan) const;

CLTimeSpan CLTimeSpan::operator-(const CLTimeSpan& TimeSpan) const;

Standard arithmetic operators to add and subtracts CLTimeSpan’s.

 

CLTimeSpan& CLTimeSpan::operator+=(const CLTimeSpan& TimeSpan);

CLTimeSpan& CLTimeSpan::operator-=(CLTimeSpan& TimeSpan);

Standard arithmetic auto increment and decrement operators.

 

CLTimeSpan CLTimeSpan::operator*(WORD Multiplier) const;

CLTimeSpan operator*(WORD Multiplier, const CLTimeSpan& TimeSpan);

CLTimeSpan CLTimeSpan::operator/(WORD divisor) const;

Standard arithmetic operators to multiply and divide CLTimeSpan’s.

 

CLTimeSpan& CLTimeSpan::operator*=(WORD Multiplier);

CLTimeSpan& CLTimeSpan::operator/=(WORD Divisor);

Standard arithmetic auto multiply and divide operators.

 

bool CLTimeSpan::operator==(const CLTimeSpan& TimeSpan) const;

bool CLTimeSpan::operator>(const CLTimeSpan& TimeSpan) const;

bool CLTimeSpan::operator>=(const CLTimeSpan& TimeSpan) const;

bool CLTimeSpan::operator<(const CLTimeSpan& TimeSpan) const;

bool CLTimeSpan::operator<=(const CLTimeSpan& TimeSpan) const;

bool CLTimeSpan::operator!=(const CLTimeSpan& TimeSpan) const;

Standard arithmetic equality operators.

 

CString CLTimeSpan::GetWindowsFormatString(LCID Locale = LOCALE_USER_DEFAULT)

Returns a CLTimeSpan::Format string appropriate for the specified windows locale as specified by 'Locale'

See Also

CLTimeSpan::Format

 

CString CLTimeSpan::Format(const CString& sFormat = GetWindowsFormatString(LOCALE_USER_DEFAULT), LCID Locale = LOCALE_USER_DEFAULT) const;

Generates a formatted string that corresponds to this CLTimeSpan object.

The sFormat string supports the following replaceable parameters:

Remarks

See Also

CLTimeSpan::GetWindowsFormatString

 

void CLTimeSpan::Serialize(CArchive& ar);

Standard MFC override to allow streaming of this CLTimeSpan to and from an archive. The space taken is 10 bytes (8 data bytes + 2 schema bytes).

Remarks

As of v3 of DTime+, the serialization is not backward compatible with earlier versions.

 

friend CArchive& operator<<(CArchive& ar, CLTimeSpan& TimeSpan);

Simply calls the Serialize method of ‘TimeSpan’, asserting that the archive ‘ar’ is storing.

 

friend CArchive& operator>>(CArchive& ar, CLTimeSpan& TimeSpan);

Simply calls the Serialize method of ‘TimeSpan’, asserting that the archive ‘ar’ is loading.

 

 

CLTimeOfDay Index

Constructors

CLTimeOfDay

Setting

Set

Static Constructors

CurrentSystemTime

CurrentLocalTime

Midnight

Midday

Static Operations

GetAMString

GetPMString

Operations

GetHours

GetMinutes

GetSeconds

GetTotalSeconds

GetAMPMHours

GetAMPMString

IsValid

Collate

GetAsSystemTime

GetAsTM

Overloaded Arithmetic Operators

operator=

operator+,-

operator+=.-=

Overloaded Equality Operators

operator==, > etc.

Display

GetWindowsFormatString

Format

Serialization

Serialize

operator<<

operator>>

 

 

CLTimeOfDay Constructors

CLTimeOfDay();

CLTimeOfDay(WORD Hour, WORD Minute, WORD Second, bool bDoAssert = true);

CLTimeOfDay(const SYSTEMTIME& st, bool bDoAssert = true);

CLTimeOfDay(const CLTimeOfDay& ltod);

CLTimeOfDay(DWORD TotalSeconds, bool bDoAssert = true);

Parameters

Hour, Minute, Second Indicates a hour, minute and second values.

st A Win32 SYSTEMTIME structure.

ltod Indicates an existing CLTimeOfDay instance.

TotalSeconds Indicates a accumulated number of seconds.

bDoAsserts if set, the constructors will assert in debug mode if any of the parameters are invalid

Remarks

 

CLTimeOfDay Set functions

CLTimeOfDay& Set();

CLTimeOfDay& Set(WORD Hour, WORD Minute, WORD Second, bool bDoAssert = true);

CLTimeOfDay& Set(const SYSTEMTIME& st, bool bDoAssert = true);

CLTimeOfDay& Set(DWORD TotalSeconds, bool bDoAssert = true);

Parameters

See CLTimeOfDay Constructors

Remarks

 

static CLTimeOfDay CLTimeOfDay::CurrentSystemTime();

Returns a CLTimeOfDay which represents the current UTC time of day as taken from the system clock.

 

static CLTimeOfDay CLTimeOfDay::CurrentLocalTime();

Returns a CLTimeOfDay which represents the current Local time of day as taken from the system clock.

 

static CLTimeOfDay CLTimeOfDay::Midnight();

Returns a CLTimeOfDay that represents midnight.

 

static CLTimeOfDay CLTimeOfDay::Midday();

Returns a CLTimeOfDay that represents midday.

 

static CString CLTimeOfDay::GetAMString(LCID Locale = LOCALE_USER_DEFAULT);

Returns the string to used for the 'AM' indicator for the specified locale.

 

static CString CLTimeOfDay::GetPMString(LCID Locale = LOCALE_USER_DEFAULT);

Returns the string to used for the 'PM' indicator for the specified locale.

 

WORD CLTimeOfDay::GetHours() const;

Returns the number of hours this CLTimeOfDay contains.

e.g. CLTimeOfDay<> x(12 , 13, 14, 15)

ASSERT(x.GetHours() == 12);

 

WORD CLTimeOfDay::GetMinutes() const;

Returns the number of minutes this CLTimeOfDay contains.

e.g. CLTimeOfDay<> x(12 , 13, 14, 15)

ASSERT(x.GetMinutes() == 13);

 

WORD CLTimeOfDay::GetSeconds() const;

Returns the number of seconds this CLTimeOfDay contains.

e.g. CLTimeOfDay<> x(12 , 13, 14, 15)

ASSERT(x.GetSeconds() == 14);

 

DWORD CLTimeOfDay::GetTotalSeconds() const;

Returns the total number of seconds this CLTimeOfDay contains.

e.g. CLTimeOfDay<> x(0 , 1, 14, 15)

ASSERT(x.GetTotalSeconds() == 74);

 

WORD  CLTimeOfDay::GetAMPMHours() const;

Returns the 12 hour version of the hour this CLTimeOfDay represents.

e.g. CLTimeOfDay<> x(17 , 13, 14, 15)

ASSERT(x.GetAMPMHour() == 5);

 

CString CLTimeOfDay::GetAMPMString(LCID Locale = LOCALE_USER_DEFAULT) const;

Returns the string to used for the 'AM'or 'PM' indicator for the specified locale for this instance's hour value.

 

bool CLTimeOfDay::IsValid() const;

Returns true if this instance is valid otherwise false.

e.g. CLTimeOfDay<> Inval;

ASSERT(IsValid(Inval) == false);

 

DWORD CLTimeOfDay::Collate() const;

Returns a long which can be used in a date collation purposes i.e. the hours value is stored as units of 10000, the minutes value is stored as units of 100 and the seconds value as units of 1.

e.g. CLTimeOfDay<> x(13, 12, 11);

ASSERT(x.Collate = 131211L);

 

bool CLTimeOfDay::GetAsSystemTime(SYSTEMTIME& SystemTime) const;

Returns a SYSTEMTIME structure representing this CLTimeOfDay

Remarks

 

bool CLTimeOfDay::GetAsTM(tm& time) const;

Returns a ‘C’ runtime tm struct version of this instance.

 

CLTimeOfDay& CLTimeOfDay::operator=(const CLTimeOfDay& Tod);

Copies a CLTimeOfDay into this CLTimeOfDay and returns a reference to this instance.

 

CLTimeOfDay CLTimeOfDay::operator+(const CLTimeSpan& TimeSpan) const;

CLTimeOfDay CLTimeOfDay::operator-(const CLTimeSpan& TimeSpan) const;

Standard arithmetic operators to add and subtracts CLTimeOfDay’s.

 

CLTimeOfDay& CLTimeOfDay::operator+=(const CLTimeSpan& TimeSpan);

CLTimeSpan& CLTimeOfDay::operator-=(CLTimeSpan& TimeSpan);

Standard arithmetic auto increment and decrement operators.

 

bool CLTimeOfDay::operator==(const CLTimeOfDay& Tod) const;

bool CLTimeOfDay::operator>(const CLTimeOfDay& Tod) const;

bool CLTimeOfDay::operator>=(const CLTimeOfDay& Tod) const;

bool CLTimeOfDay::operator<(const CLTimeOfDay& Tod) const;

bool CLTimeOfDay::operator<=(const CLTimeOfDay& Tod) const;

bool CLTimeOfDay::operator!=(const CLTimeOfDay& Tod) const;

Standard arithmetic equality operators.

 

CString CLTimeOfDay::GetWindowsFormatString(LCID Locale = LOCALE_USER_DEFAULT)

Returns a CLTimeOfDay::Format string appropriate for the specified windows locale as specified by 'Locale'

See Also

CLTimeOfDay::Format

 

CString CLTimeOfDay::Format(const CString& sFormat = GetWindowsFormatString(LOCALE_USER_DEFAULT), LCID Locale = LOCALE_USER_DEFAULT) const;

Generates a formatted string that corresponds to this CLTimeOfDay object.

The sFormat string supports the following replaceable parameters:

Remarks

See Also

CLTimeOfDay::GetWindowsFormatString

 

void CLTimeOfDay::Serialize(CArchive& ar);

Standard MFC override to allow streaming of this CLTimeOfDay to archive. The space taken is exactly 6 bytes (4 data bytes + 2 schema bytes).

Remarks

As of v3 of DTime+, the serialization is not backward compatible with earlier versions.

 

friend CArchive& operator<<(CArchive& ar, CLTimeSpan& Tod);

Simply calls the Serialize method of ‘Tod’, asserting that the archive ‘ar’ is storing.

 

friend CArchive& operator>>(CArchive& ar, CLTimeSpan& Tod);

Simply calls the Serialize method of ‘Tod’, asserting that the archive ‘ar’ is loading.

 

 

 

CLDate Index

Constructors

CLDate

Seting

Set

Static Constructors

CurrentSystemTime

CurrentLocalTime

Operations

GetCDate

GetCLTimeOfDay

GetDate

GetAsSystemTime

GetAsFileTime

GetAsCOleDateTime

GetAsTM

AddYear

AddMonth

AddWeek

IsValid

Overloaded Arithmetic Operators

operator=

operator+,-

operator+=.-=

operator++

operator--

Overloaded Equality Operators

operator==, > etc.

Display

GetWindowsFormatString

Format

Serialization

Serialize

operator<<

operator<<

 

 

CLDate Constructors

CLDate();

CLDate(long Year, WORD month, WORD Day, WORD Hour, WORD Minute, WORD Second, bool bDoAssert = true);

CLDate(const SYSTEMTIME& SystemTime, bool bDoAssert = true);

CLDate(const FILETIME& FileTime, bool bDoAssert = true);

CLDate(long Year, WORD month, WORD WeekOfMonth, DayOfWeek dow, WORD Hour, WORD Minute, WORD Second, bool bDoAssert = true);

CLDate(long Days, CDate::DateEpoch e, WORD Hour, WORD Minute, WORD Second, bool bDoAssert = true);

CLDate(const CLDate& ld);

CLDate(const CTime& ctime, bool bDoAssert = true);

CLDate(const CDate<TCALENDAR>& Date, const CLTimeOfDay& Tod);

CLDate(const COleDateTime& oleTime, bool bDoAssert = true);

Parameters

Year, Month, Day Indicates a year, month and day.

Hour, Minute, Second Indicates a hour, minute and second values.

SystemTime A Win32 SDK SYSTEMTIME structure.

FileTime A Win32 SDK FILETIME structure.

ld Indicates a CLDate object that already exists.

ctime Indicates a CTime object that already exists.

WeekOfMonth The week of the month (0 - 5).

DayOfWeek The day of the week e.g. CDate::Sunday.

oleTime An OLE Date.

bDoAsserts if set, the constructors will assert in debug mode if any of the parameters are invalid

Remarks

 

CLDate Set functions

CLDate& Set();

CLDate& Set(long Year, WORD month, WORD Day, WORD Hour, WORD Minute, WORD Second, bool bDoAssert = true);

CLDate& Set(const SYSTEMTIME& st, bool bDoAssert = true);

CLDate& Set(const FILETIME& FileTime, bool bDoAssert = true);

CLDate& Set(long Year, WORD month, WORD WeekOfMonth, DayOfWeek dow, WORD Hour, WORD Minute, WORD Second, bool bDoAssert = true);

CLDate& Set(long Days, CDate::DateEpoch e, WORD Hour, WORD Minute, WORD Second, bool bDoAssert = true);

CLDate& Set(const CTime& ctime, bool bDoAssert = true);

CLDate& Set(const CDate<TCALENDAR>& Date, const CLTimeOfDay& Tod);

CLDate& Set(const COleDateTime& oleTime, bool bDoAssert = true);

Parameters

See CLDate Constructors

Remarks

 

static CLDate CLDate::CurrentSystemTime(bool bDoAssert = true);

Returns a CLDate which represents the current UTC date as taken from the system clock.

 

static CLDate CLDate::CurrentLocalTime(bool bDoAssert = true);

Returns a CLDate which represents the current local date as taken from the system clock.

 

CDate<TCALENDAR> CLDate::GetCDate() const;

Returns a CDate that represents the date part of this instance. Allows co-ordinated access to all the range of CDate functions.

Remarks

 

CLTimeOfDay<> CLDate::GetCLTimeOfDay() const;

Returns a CLTimeOfDay that represents the time of day part of this long date. Allows co-ordinated access to all the range of CLTimeOfDay functions.

Remarks

 

DateLS CLDate::GetDate() const;

Returns a DateLS structure for this instance.

 

bool CLDate::GetAsSystemTime(SYSTEMTIME& SystemTime) const;

Returns a Win32 SDK SYSTEMTIME struct version of this instance.

Remarks

 

bool CLDate::GetAsFileTime(FILETIME& FileTime) const;

Returns a Win32 SDK FILETIME struct version of this instance.

 

bool CLDate::GetAsCOleDateTime(COleDateTime& OleDateTime) const;

Returns a COleDateTime representation of this instance. This may prove useful in environments where you have to integrate with VB, ODBC or DAO.

 

bool CLDate::GetAsTM(tm& time);

Returns a ‘C’ runtime tm struct version of this instance.

 

void CLDate::AddYear(int Years = 1);

Adds a number of years to this instance.

 

void CLDate::AddMonth(int Months = 1);

Adds a number of months to this instance.

Remarks

 

void CLDate::AddWeek(int Weeks = 1);

Adds a number of weeks i.e. 7 days to this instance.

 

bool CLDate::IsValid() const;

Returns true if this instance is valid otherwise false.

e.g. CLDate Inval;

ASSERT(IsValid(Inval) == false);

 

CLDate& CLDate::operator=(const CLDate& ld);

Copies a CLDate into this CLDate and returns a reference to this instance.

 

CLDate CLDate::operator+(const CLTimeSpan& ts);

CLTimeSpan CLDate::operator-(const CLDate& ld);

CLDate CLDate::operator-(const CLTimeSpan& ts);

Standard arithmetic operators to add and subtracts CLDate’s.

 

CLDate& CLDate::operator+=(const CLTimeSpan& ts);

CLDate& CLDate::operator-=(const CLTimeSpan& ts);

Standard auto increment and decrement operators.

 

CLDate& CLDate::operator++();

Standard arithmetic increment operator. Adds one day to this instance

 

CLDate& CLDate::operator--();

Standard arithmetic decrement operator. Subtracts one day from this instance.

 

bool CLDate::operator==(const CLDate& ld);

bool CLDate::operator>(const CLDate& ld);

bool CLDate::operator>=(const CLDate& ld);

bool CLDate operator<(const CLDate& ld);

bool CLDate operator<=(const CLDate& ld);

bool CLDate operator!=(const CLDate& ld);

Standard arithmetic equality operators.

 

CString CLDate::GetWindowsFormatString(LCID Locale = LOCALE_USER_DEFAULT)

Returns a CLDate::Format string appropriate for the specified windows locale as specified by 'Locale'

See Also

CLDate::Format

 

CString CLDate::Format(const CString& sFormat = GetWindowsFormatString(LOCALE_USER_DEFAULT), LCID Locale = LOCALE_USER_DEFAULT) const;

Generates a formatted string that corresponds to this CLDate object.

The sFormat string supports the following replaceable parameters:

Remarks

See Also

CLDate::GetWindowsFormatString

 

void CLDate::Serialize(CArchive& ar);

Standard MFC override to allow streaming of this CLDate to archive. The space taken is exactly 11 bytes (9 data bytes + 2 schema bytes).

Remarks

As of v3 of DTime+, the serialization is not backward compatible with earlier versions.

 

friend CArchive& operator<<(CArchive& ar, CLDate& ld);

Simply calls the Serialize method of ‘ld’, asserting that the archive ‘ar’ is storing.

 

friend CArchive& operator>>(CArchive& ar, CLDate& ld);

Simply calls the Serialize method of ‘ld’, asserting that the archive ‘ar’ is loading.

 

 

 

Structures / Enums / Consts used by the Classes

namespace DTimePlus
{
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
};

enum MoslemMonth
{
  Muharram = 1,
  Safar = 2,
  Rabi_Al_Awwal = 3,
  Rabi_Ath_Thani = 4,
  Jumada_l_Ula = 5,
  Jumada_Ath_Tania = 6,
  Rajab = 7,
  Sha_ban = 8,
  Ramdadan = 9,
  Shawwal = 10,
  Dhu_l_Qa_da = 11,
  Dhu_l_Hijja = 12
};

enum DayOfWeek
{
  Sunday = 1,
  Monday = 2,
  Tuesday = 3,
  Wednesday = 4,
  Thursday = 5,
  Friday = 6,
  Saturday = 7
};

enum DateEpoch
{
  EPOCH_JD = 0,
  EPOCH_MJD = 1,
  EPOCH_1900 = 2,
  EPOCH_1950 = 3,
  EPOCH_CTIME = 4,
  EPOCH_2000 = 5,
  EPOCH_GREG = 6
};

struct DateS
{
  long lYear;
  WORD wMonth;
  WORD wDay;
  DayOfWeek weekday;
  WORD wYearday;
};

struct DateLS
{
  long lYear;
  WORD wMonth;
  WORD wDay;
  DayOfWeek weekday;
  WORD wYearday;
  WORD wHour;
  WORD wMinute;
  WORD wSecond;
};
} //namespace DTimePlus

Remarks

 

 

 

Future Enhancements

 

 

 

UI Support

The UI support for DTime+ is provided by the DTime+UI.h module. This provides a collection of standard DDX functions to allow a date to be mapped to a CDate<CGregorianCalendar> instance and a time of day to be mapped to a CLTimeOfDay instance. To provide data entry for CLDate, you should provide 2 UI controls, one for the CDate component and another for the CLTimeOfDay component. Note that no UI support is currently provided for the CLTimeSpan class or the Julian or Moslem calendars. For this you will need to roll your own by using something like a standard edit control or a masked edit control. If people feel that this would be a nice addition to the framework, then I would consider developing a clone of the standard Windows date / time controls to support this functionality. The UI used for both of these DDX functions uses the standard Date Time control as provided by Windows (and as wrapped by MFC with CDateTimeCtrl).

Usage of the Data entry Routines

Methods

DDX_DateTimeCtrl

 

void DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, DTimePlus::CDate<CGregorianCalendar>& value);

void DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, DTimePlus::CLTimeOfDay<>& value);

Depending on the overloaded function called, it transfers a CDate or CLTimeOfDay to and from the screen. This function would normally be called in your classes DoDataExchange function

Parameters

pDX Standard MFC data exchange class.

nIDC The resource ID of the date and time picker control associated with the member variable.

value Value to retrieve/set in the UI.

Remarks

 

 

 

Contacting the Author

PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
13 April 2007