XDate
XDate includes implementation of the classesCGregorianDate, CIsoDate, and CFiscalDate. Please click on the following links for more information:
- CGregorianDate: manipulating dates in the Gregorian calendar
- CIsoDate: manipulating ISO-8601 dates; and XDateCalc, a calculator to display Gregorian and ISO dates
- CFiscalDate: manipulating fiscal dates, weeks, quarters, and years; and XFisCal, a program that lets you create a printable fiscal calendar
|
The calendar in use in most of the world today is the Gregorian calendar, which came into common use beginning in 1582 AD, when it was decreed by Pope Gregory XIII, after whom it was named. Prior to that, the Julian calendar - introduced by Julius Caesar in 46 BC - was in continuous use, and remained in use into the 20th century in some parts of the world. In modern times, there have been several attempts to standardize the formatting of dates. The most successful of these efforts is ISO 8601. This comprehensive standard is now widely used in timestamping documents, log files, emails, and other computer-generated files. It also introduced what has been called the ISO date/time, which is actually a set of rules for the representation of dates and times. ISO 8601 uses YYYY-MM-DD big-endian date notation, and also introduced the idea of ISO week dates, which are specified by the ISO week-numbered year in the format YYYY, a week number in the format ww prefixed by the letter W, and the weekday number, a digit from 1 through 7, beginning with Monday and ending with Sunday. |
CGregorianDate
To work with dates in any software program, you first have to decide how you will store dates internally. Currently, there are several standard date types to choose from:- time_t - a 32-bit long integer used to store time values (seconds since midnight January 1, 1970 AD). There is also a 64-bit version. The 32-bit version wraps on January 18, 2038 AD.
- struct tm - this struct contains easily-accessible members for date and time.
-
DATE - this type
implements date and time as a floating point number and is the basis for
COleDateTime. Its range is January 1, 100 AD, to December 31, 9999 AD. - SYSTEMTIME - This struct is used system-wide for date and time storage. It has handy members for accessing individual time elements. Its range is 1601 AD through 30827 AD.
-
FILETIME - this struct is normally used only for dealing with filesystem times. To actually use it, you would normally convert it to a
SYSTEMTIME. Note that FAT records times on disk in local time, while NTFS records times on disk in UTC (aka GMT). -
CTime - a very
popular MFC class based on time_t, has a corresponding
CTimeSpanclass. -
COleDateTime -
another popular MFC class with a larger range than
CTime, has a correspondingCOleDateTimeSpanclass. See also this article. - DateTime - this struct is used in the .Net framework to represent date and time. It has many handy member functions. Its range is January 1, 1 AD to December 31, 9999 AD.
Date Types
Unfortunately, none of these date types offer a comprehensive way of handling all the varieties of dates that commonly occur in today's electronic documents. Here are some that are not handled:-
ISO 8601 week date formats -
The ISO 8601 standard can be found
here and here.
While ISO 8601 specifies many formats that use the Gregorian calendar, it also introduces an entirely new date representation called
ISO week dates. You
can read the details in ISO 8601, ¶2.2.10 and ¶3.2.2.
In the ISO 8601 system of calendar weeks, there can be 52 or 53 weeks in an ISO 8601 year. The first week of the ISO year (just like all ISO weeks) begins on a Monday, and specifically includes January 4 (ISO 8601 ¶3.2.2). ISO 8601 week dates can be represented by YYYY-Www-D, where YYYY is the ISO year, ww is the 2-digit week number( 1..53), and D is the day number (1..7) within the week (Monday = 1, Sunday = 7). Thus, an ISO year may include up to three days from the preceding Gregorian year (if January 4 falls on a Sunday). In the same way, the end of an ISO year may include up to three days from the following Gregorian year. Example of this format: 1994-W52-7, which is January 1, 1995.
- ISO 8601 ordinal dates - Another ISO 8601 date format is YYYY-DDD, where YYYY is the year and DDD is the sequential day number (1..366) within the year. ISO 8601 (see ¶4.1.3ff) calls this an ordinal date. Example of this format: 1985-102.
- Julian day numbers - Julian day numbers (or, as JR Stockton points out, chronological Julian day numbers, since integer Julian day numbers do not include the fractional time, but are simply a count of days; read more about this here and here) are useful because they are simple to manipulate. Since Julian day numbers (I will omit "chronological" for brevity) are a monotonic sequence of integers, it is very easy to determine date differences using them. There are standard formulas for calculating Julian day numbers; see here.
-
Day and month names - You can obtain the day and month names (both full and abbreviated) by using the Win32 function
GetLocaleInfo(). But what if you're in New York and wanted to retrieve and output the names appropriate for Europe or Asia? Or wanted to always output the US names, regardless of where you're located? Or wanted to output the names that are appropriate for some other area? TheCGregorianDateclass provides this flexibility in a convenient, unified manner. - Fiscal calendars - There are many different types of calendars used by accounting and government entities, for both budgeting and scheduling purposes. These fiscal calendars are not always aligned on the Gregorian year; they differ in the start date (some start on January 1, others October 1, etc.); in whether the first week of the fiscal year starts on the first full week; and in whether weeks start on Sunday or Monday. Fiscal calendars are obviously crucial to businesses and governments, and yet none of the above date types provide any support for them.
To meet these various requirements, I created XDate.h.
XDate.h
The file XDate.h includes implementation of the classesCGregorianDate, CIsoDate, and CFiscalDate. This article discusses
CGregorianDate; Parts 2 and 3 discuss CIsoDate and
CFiscalDate.
At the end of this article, there is a list of CGregorianDate class members.
CGregorianDate implements a class based on the Gregorian calendar. Its data members are:
//=============================================================================
// Data
//=============================================================================
private:
// Note that all m-d-y values are one-based
int month; // 1 = January, ..., 12 = December
int day; // 1..LastDayOfMonth()
int year; // 1583..INT_MAX
Besides the usual month-day-year (MDY), CGregorianDate has constructors for many commonly used date types:
DATEFILETIMEJulian day numberordinal date YYYYDDDSYSTEMTIMEtime_tstruct tm
There are also retrieval functions that return the current CGregorianDate date in these formats.
CGregorianDate implements overloaded math operators for +, -, ++, --, +=, and -=, as well as logical compare operators ==, !=, <, >, <=, and >=.
One of 24 carved wheels at the Konark Sun Temple in Orissa, India, built by King Narasimhadeva about 1250 AD to honor the sun god Surya. The temple symbolizes the passage of time, which is under the sun god's control. It takes the form of a huge chariot for the sun god, with 12 pairs of stone-carved wheels (representing the 12 months of the year) and a team of seven galloping horses (representing the days of the week). |
CGregorianDate Construction
Examples of CGregorianDate construction:
-
Construction from Gregorian date MM/DD/YYYY
CGregorianDate gd(3, 17, 2009);
-
Construction from CGregorianDate object
CGregorianDate gd(3, 17, 2009); CGregorianDate gd2(gd); or CGregorianDate gd2 = gd; -
Construction from current time
CGregorianDate gd(CGregorianDate::GetCurrentTime()); or CGregorianDate gd = CGregorianDate::GetCurrentTime(); -
Construction from time_t
time_t t; time(&t); CGregorianDate gd(t); -
Construction from struct tm
time_t t; time(&t); struct tm now = *localtime(&t); CGregorianDate gd(now); -
Construction from SYSTEMTIME
SYSTEMTIME st; GetLocalTime(&st); CGregorianDate gd(st); -
Construction from Julian day number
CGregorianDate gd(2454908);
-
Construction from ordinal date YYYYDDD
CGregorianDate gd(2009, 76);
CGregorianDate Usage
Once you have created aCGregorianDate object, you can use class functions to find out if the date is a leap year (IsLeapYear()), get its Julian day number (GetJulianDayNumber()), get its Excel serial date (GetExcelSerialDatePC()), and get month name (GetMonthNameForLocale()) and day name (GetDayNameForLocale()) for the date. Of course, at any time you can retrieve the date information (GetDay(), GetMonth(), GetYear()), or check if the date is valid (IsValidDate()).
Example: Find a Recurring Date
Your club meets on the second Tuesday of every month. You want to list all the club meeting dates for 2009: // from XDateTestDlg.cpp
TCHAR szDayName[100];
TCHAR szMonthName[100];
CGregorianDate gd8(1, 6, 2009); // Tuesday
gd8.GetDayNameForLocale(szDayName, sizeof(szDayName)/sizeof(TCHAR)-1);
m_List.Printf(CXListBox::Blue, CXListBox::White, 0,
_T("Test 8: Find recurring date - 2nd %s of the month"), szDayName);
for (m = 1; m <= 12; m++)
{
gd8.Set(m, 1, 2009);
gd8.GetMonthNameForLocale(szMonthName, sizeof(szMonthName)/sizeof(TCHAR)-1);
for (int nTuesdays = 0; nTuesdays < 2; gd8++)
{
if (gd8.GetDayOfWeek() == CGregorianDate::Tuesday)
nTuesdays++;
}
gd8--;
m_List.Printf(CXListBox::Black, CXListBox::White, 0,
_T(" %s %d"), szMonthName, gd8.GetDay());
}
The above code produces this output:
Test 8: Find recurring date - 2nd Tuesday of the month
January 13
February 10
March 10
April 14
May 12
June 9
July 14
August 11
September 8
October 13
November 10
December 8
Example: Determining the Delivery Date
You need to find the delivery date for a package that you are sending. You know it will take 14 business days to get there (today is May 1): // from XDateTestDlg.cpp
m_List.Printf(CXListBox::Blue, CXListBox::White, 0,
_T("Test 9: Find delivery date"));
gd8 = CGregorianDate::GetCurrentTime();
gd8.AddBusinessDays(14);
m_List.Printf(CXListBox::Black, CXListBox::White, 0,
_T(" Delivery will be on %d/%d/%d"),
gd8.GetYear(), gd8.GetMonth(), gd8.GetDay());
The above code produces this output:
Test 9: Find delivery date
Delivery will be on 2009/5/21
Example: Find all the Mondays in October
You want to find all the Mondays in October: // from XDateTestDlg.cpp
TCHAR szMonthName[100];
gd8.Set(10, 5, 2009); // Monday
gd8.GetDayNameForLocale(szDayName, sizeof(szDayName)/sizeof(TCHAR)-1);
gd8.GetMonthNameForLocale(szMonthName, sizeof(szMonthName)/sizeof(TCHAR)-1);
m_List.Printf(CXListBox::Blue, CXListBox::White, 0,
_T("Test 10: Find %ss in %s"), szDayName, szMonthName);
gd8.Set(10, 1, 2009);
while (gd8.GetMonth() == 10)
{
if (gd8.GetDayOfWeek() == CGregorianDate::Monday)
m_List.Printf(CXListBox::Black, CXListBox::White, 0,
_T(" %s %d"), szMonthName, gd8.GetDay());
gd8++;
}
The above code produces this output:
Test 10: Find Mondays in October
October 5
October 12
October 19
October 26
Example: Days until Christmas
You want to find the number of days until Christmas: // from XDateTestDlg.cpp
m_List.Printf(CXListBox::Blue, CXListBox::White, 0,
_T("Test 11 Find days until Christmas"));
gd8 = CGregorianDate::GetCurrentTime();
n = gd8.GetDays(12, 25, gd8.GetYear());
m_List.Printf(CXListBox::Black, CXListBox::White, 0,
_T(" Days until Christmas = %d"), n);
The above code produces this output:
Test 11 Find days until Christmas
Days until Christmas = 261
Please see XDateTestDlg.cpp for more examples of how to use CGregorianDate.
CGregorianDate Date Formatting
CGregorianDate uses
strftime()
to implement date formatting. Here are some sample formats that can be used with
CGregorianDate::Format():
| To get this date string | Use this format |
| March 17, 2009 | %B %#d, %Y |
| March 2009 | %B %Y |
| Tuesday, March 17, 2009 | %A, %B %#d, %Y |
| Tue 17 | %a %#d |
| 17 Mar 2009 | %#d %b %Y |
| 17/3/2009 | %#d/%#m/%Y |
| 3/17/2009 | %#m/%#d/%Y |
| 03/17/09 | %m/%d/%y |
| 3/17 | %#m/%#d |
| 17/03/09 | %d/%m/%y |
| 2009076 | %Y%j |
| 09076 | %y%j |
| 2009-03-17 | %Y-%m-%d |
CGregorianDate Debugging
CGregorianDate provides the following debugging facilities:
-
virtual void Trace(LPCTSTR lpszMsg = NULL) const - This virtual function can be called anytime to write the month, day, and year, along with an optional message, to
OutputDebugString(). The non-MFC XTrace.h is used to write the output when_DEBUGis defined, just like MFC's TRACE. To enable this, un-comment the line that is highlighted below://============================================================================= // TRACE output //============================================================================= // if you want to see the TRACE output, un-comment this line: //#define XDATE_ENABLE_TRACE #undef TRACE_XDATE #ifdef XDATE_ENABLE_TRACE #include "XTrace.h" // non-MFC TRACE #define TRACE_XDATE TRACE #else #define TRACE_XDATE __noop #endif -
virtual void AssertValid() const - This virtual function can be called anytime to verify the date and display a diagnostic message via
_ASSERTE(when_DEBUGis defined). - virtual void Dump() const - This virtual function may be overriden to provide custom debug output.
If you want to use the CGregorianDate Trace facility, don't forget to un-comment the line shown above, and also include XTrace.h in your project directory.
XDateTest
The demo application XDateTest.exe tests the various features and APIs of the XDate classes:
How To Use
To integrate XDate into your own program, you first need to add XDate.h to your project.
If you want to use the CGregorianDate Trace facility, also include XTrace.h in your project directory.
Next, include XDate.h in the module where you want to use the XDate classes.
For more details on how to use, please see XDateTestDlg.cpp.
CGregorianDate Class Members
| Construction | ||
| CGregorianDate() | Default constructor | |
| CGregorianDate(const CGregorianDate& gd) | Copy constructor | |
| CGregorianDate(const DATE date) | OLE DATE; used by COleDateTime | |
| CGregorianDate(const FILETIME& ft) | Filesystem FILETIME | |
| CGregorianDate(int jdn) | Chronological Julian day number | |
| CGregorianDate(int y, int d) | Ordinal date YYYYDDD | |
| CGregorianDate(int m, int d, int y) | Construction from month, day, year; earliest day is 1/1/1583 AD | |
| CGregorianDate(const struct tm& t) | C runtime; usually set from time_t | |
| CGregorianDate(const SYSTEMTIME& st) | System SYSTEMTIME | |
| CGregorianDate(time_t t) | C runtime; seconds since 1 Jan 1970 | |
Assignment |
||
| CGregorianDate& operator=(const CGregorianDate& gd) | CGregorianDate object | |
| CGregorianDate& operator=(const DATE& date) | OLE DATE; used by COleDateTime | |
| CGregorianDate& operator=(const FILETIME& ft) | Filesystem FILETIME | |
| CGregorianDate& operator=(const int& jdn) | Chronological Julian day number | |
| CGregorianDate& operator=(const struct tm& t) | C runtime; usually set from time_t | |
| CGregorianDate& operator=(const SYSTEMTIME& st) | System SYSTEMTIME | |
| CGregorianDate& operator=(const time_t& t) | C runtime; seconds since 1 Jan 1970 | |
Attributes |
||
| virtual bool GetAbbreviatedDayNameForLocale(LPTSTR lpszDayName, DWORD dwSize) const | Returns abbreviated day name for current day for system default locale as returned by GetLocaleInfo(). | |
| virtual bool GetAbbreviatedDayNameForLocale(LCID locale, LPTSTR lpszDayName, DWORD dwSize) const | Returns abbreviated day name for current day for specified locale as returned by GetLocaleInfo(). | |
| bool GetAbbreviatedDayNameForUS(LPTSTR lpszDayName, DWORD dwSize) const | Returns abbreviated day name for current day for US. | |
| virtual bool GetAbbreviatedMonthNameForLocale(LPTSTR lpszMonthName, DWORD dwSize) const | Returns abbreviated month name for system default locale for current month as returned by GetLocaleInfo(). | |
| virtual bool GetAbbreviatedMonthNameForLocale(LCID locale, LPTSTR lpszMonthName, DWORD dwSize) const | Returns abbreviated month name for current month for specified locale as returned by GetLocaleInfo(). | |
| bool GetAbbreviatedMonthNameForUS(LPTSTR lpszMonthName, DWORD dwSize) const | Returns abbreviated month name for current month for US. | |
| int GetBusinessDays(int m, int d, int y) const | Returns number of business days (see IsBusinessDay()) between the current date and the mdy date. Returns < 0 if mdy is in past, > 0 if mdy is in future. | |
| int GetBusinessDays(const CGregorianDate& gd) const | Returns number of business days (see IsBusinessDay()) between the current date and the gd date. Returns < 0 if gd is in past, > 0 if gd is in future. | |
| int GetCentury() | Returns century; eg, returns 19 for 1985. | |
| static CGregorianDate GetCurrentTime() | Returns a CGregorianDate object that represents the current time. | |
| int GetDay() const | Returns current day of month (1..31). | |
| int GetDayOfWeek() const | Returns day of week; Monday = 0, Sunday = 6. | |
| virtual bool GetDayNameForLocale(LPTSTR lpszDayName, DWORD dwSize) const | Returns day name for current day for the system default locale as returned by GetLocaleInfo(). | |
| virtual bool GetDayNameForLocale(LCID locale, LPTSTR lpszDayName, DWORD dwSize) const | Returns day name for current day for the specified locale as returned by GetLocaleInfo(). | |
| bool GetDayNameForUS(LPTSTR lpszDayName, DWORD dwSize) const | Returns day name for current day for US. | |
| int GetDays(int m, int d, int y) const | Returns number of days between the current date and the mdy date. Returns < 0 if mdy is in past, > 0 if mdy is in future. | |
| int GetDays(const CGregorianDate& gd) const | Returns number of days between the current date and the gd date. Returns < 0 if gd is in past, > 0 if gd is in future. | |
| static int GetExcelSerialDateMAC(int m, int d, int y) | Returns the MAC Excel serial date, a monotonic sequence of integers beginning with 0 = 1/1/1904. | |
| int GetExcelSerialDateMAC() const | Returns the MAC Excel serial date for the current date. | |
| static int GetExcelSerialDatePC(int m, int d, int y) | Returns the PC Excel serial date, a monotonic sequence of integers beginning with 1 = 1/1/1900. A special case is made for 2/29/1900 (an invalid date), because of a bug in Excel/Lotus 123. | |
| int GetExcelSerialDatePC() const | Returns the PC Excel serial date for the current date. | |
| bool GetGregorian(int& m, int& d, int& y) const | Returns the mdy values for the current date. Returns true if current date is valid. | |
| bool GetIso(int& w, int& d, int& y) const | Returns ISO week, day, and year for current date. | |
| static int GetJulianDayNumber(int m, int d, int y) | Returns Julian day number for mdy. | |
| int GetJulianDayNumber() const | Returns Julian day number for current date. | |
| int GetModifiedJulianDayNumber() const | Returns modified Julian day number for current date; this is the Julian day number - 2400001. It offers smaller magnitude numbers at a cost of reduced range. | |
| int GetMonth() const | Returns current month (1..12). | |
| virtual bool GetMonthNameForLocale(LPTSTR lpszMonthName, DWORD dwSize) const | Returns month name for current month for the system default locale as returned by GetLocaleInfo(). | |
| virtual bool GetMonthNameForLocale(LCID locale, LPTSTR lpszMonthName, DWORD dwSize) const | Returns month name for current month for the specified locale as returned by GetLocaleInfo(). | |
| bool GetMonthNameForUS(LPTSTR lpszMonthName, DWORD dwSize) const | Returns month name for current month for US. | |
| static int GetOrdinalDayOfYear(int m, int d, int y) | Returns day within year (1..366) for MDY. | |
| int GetOrdinalDayOfYear() const | Returns day within year (1..366) for current date. | |
| virtual TCHAR * GetOrdinalSuffix(int n) const | Returns pointer to suffix string for n; st for 1 *1st), nd for 2 (2nd), etc. | |
| bool GetOrdinalSuffixForDay(LPTSTR lpszSuffix, DWORD dwSize) const | Returns suffix string for current month day. | |
| bool GetSystemTime(SYSTEMTIME& SystemTime) const | Returns SYSTEMTIME value for current date. Returns false if date is not a valid SYSTEMTIME date (before 1602). | |
| bool GetTm(struct tm& t) const | Fills in tm struct with current month, day, and year. Returns false if date is not a valid C runtime date (before 1/1/1970). | |
| static int GetWeekNumber(int m, int d, int y, bool bMondayStart) | Returns week number (1..52) for MDY. If bMondayStart is true, week begins on Monday, otherwise week begins on Sunday. | |
| int GetWeekNumber(bool bMondayStart) const | Returns week number (1..52) for current date. If bMondayStart is true, week begins on Monday, otherwise week begins on Sunday. | |
| int GetYear() const | Returns current year (1583...). | |
| int GetYearWithoutCentury() const | Returns year without century; eg, returns 85 for 1985. | |
| virtual bool IsBusinessDay() const | Returns true if current date is a business day; the default implementation equates business days with week days that are not holidays. | |
| virtual bool IsHoliday() const | Returns true if current date is a holiday; the default implementation returns false. | |
| static bool IsIsoYearLong(int y) | Returns true if ISO year y contains 53 weeks, false if it contains 52. | |
| bool IsIsoYearLong() const | Returns true if ISO year of current date contains 53 weeks, false if it contains 52. | |
| static bool IsLeapYear(int y) | Returns true if year y is leap year, false if not. | |
| bool IsLeapYear() const | Returns true if year of current date is leap year, false if not. | |
| static bool IsValidDate(int m, int d, int y) | Returns true if mdy is a valid date, false if not. | |
| bool IsValidDate() const | Returns true if current date is a valid date, false if not. | |
| bool IsValidJulianDayNumber() const | Returns true if current date is a valid Julian day, false if not. | |
| virtual bool IsWeekDay() const | Returns true if current date is a week day; the default implementation equates week days with non-weekend days. | |
| virtual bool IsWeekEnd() const | Returns true if current date is a weekend day; the default implementation equates weekend days with Saturday or Sunday. | |
| static int LastDayOfMonth(int m, int y) | Returns last day (month size) of month m, year y. | |
| int LastDayOfMonth() const | Returns last day (month size) of current month. | |
| static bool OrdinalDateToGregorian(int ord_year, int ord_day, int& month, int& month_day) | Converts ISO date YYYYDDD to month and month day. | |
| bool Set(int m, int d, int y) | Sets the current month, day, and year. Returns true if date is valid | |
| void SetDay(int d) | Sets the current day to d. | |
| bool SetFromExcelSerialDateMAC(int esd) const | Sets the date from the MAC Excel serial date esd. | |
| bool SetFromExcelSerialDatePC(int esd) const | Sets the date from the PC Excel serial date esd. Serial dates below 61 are not allowed, because a bug in Excel caused 60 (2/29/1900) to be considered a valid date. | |
| bool SetFromIso(int w, int d, int y) | Sets the current date to ISO date wdy. Returns true if date is valid. | |
| bool SetFromJulianDayNumber(int jdn) | Sets the current date to Julian day number jdn. Returns true if date is valid. | |
| bool SetFromModifiedJulianDayNumber(int mjdn) | Sets the current date to the modified Julian day number mjdn. Returns true if date is valid. | |
| bool SetFromOrdinalDate(int ord_year, int ord_day) | Sets the current date to the ISO ordinal date YYYYDDD. Returns true if date is valid. | |
| bool SetFromSystemTime(const SYSTEMTIME& SystemTime) | Sets the current date to the date represented by the SYSTEMTIME SystemTime. Returns true if date is valid. | |
| bool SetFromSystemTime() | Sets the current date to the date returned by the system function GetLocalTime(). Returns true if date is valid. | |
| bool SetFromTm(const struct tm& t) | Sets the current date to the date represented by tm. Returns true if date is valid. | |
| void SetMonth(int m) | Sets the current month to m. | |
| void SetYear(int y) | Sets the current year to y. | |
Logical Operators |
||
| bool operator==(const CGregorianDate& rhs) const | Returns true if dates are equal. | |
| bool operator!=(const CGregorianDate& rhs) const | Returns true if dates are not equal. | |
| bool operator<(const CGregorianDate& rhs) const | Returns true if lhs is less than rhs. | |
| bool operator>(const CGregorianDate& rhs) const | Returns true if lhs is greater than rhs. | |
| bool operator<=(const CGregorianDate& rhs) const | Returns true if lhs is less than or equal to rhs. | |
| bool operator>=(const CGregorianDate& rhs) const | Returns true if lhs is greater than or equal to rhs | |
Math Operators |
||
| CGregorianDate& operator+(int days) | Add days to current date. | |
| CGregorianDate& operator-(int days) | Subtract days from current date. | |
| CGregorianDate& operator+=(int days) | Add days to current date. | |
| CGregorianDate& operator-=(int days) | Subtract days from current date. | |
| CGregorianDate& operator++() | Add one day to current date (prefix). | |
| CGregorianDate& operator--() | Subtract one day from current date (prefix). | |
| CGregorianDate& operator++(int) | Add one day to current date (postfix). | |
| CGregorianDate& operator--(int) | Subtract one day from current date (postfix). | |
Operations |
||
| bool AddBusinessDays(int n) | Add n business days (see IsBusinessDay()) to current date. Returns true if resulting date is valid. | |
| bool AddDays(int n) | Add n days to current date. Returns true if resulting date is valid. | |
| bool AddMonths(int n) | Add n months to current date. Returns true if resulting date is valid. | |
| bool AddWeeks(int n) | Add n weeks to current date. Returns true if resulting date is valid. | |
| bool AddYears(int n) | Add n years to current date. Returns true if resulting date is valid. | |
| bool FindIsoYearStart() | Sets the current date to the start of the ISO year, as defined by ISO 8601. This is the first Monday that falls on or before January 4. Returns true if resulting date is valid. | |
| size_t Format(LPTSTR lpszDest, size_t maxsize, LPCTSTR format) const | Formats the current date with _tcsftime(). The date string is returned in lpszDest. Its size is returned by Format(). | |
| static bool MDYFromOleDate(DATE dtSrc, int& m, int& d, int& y) | Returns MDY from OLE DATE value. Returns true if resulting date is valid. | |
| static bool OleDateFromMDY(DATE& dtDest, int m, int d, int y) | Returns OLE DATE value from MDY. Returns false if MDY is not a valid date (before 1583). | |
Dump/Trace |
||
| virtual void AssertValid() const | Virtual function. By default returns true if current date is valid. | |
| virtual void Dump() const | Virtual function. By default outputs the current date using OutputDebugString(). | |
| virtual void Trace(LPCTSTR lpszMsg = NULL) const | Virtual function. By default outputs an optional message and the current date using OutputDebugString(). | |
References
- Date and Time Formats, web site maintained by JR Stockton. Comprehensive and accurate discussion of date systems and formats.
- The Hermetic Systems web site has many articles discussing dates and calendars. Very informative.
- Gregorian calendar Wikipedia entry.
- Julian calendar Wikipedia entry.
- Wikipedia has some background on ISO 8601 here.
- The ISO 8601 standard can be found here and here.
Revision History
Version 1.0
- Initial release
Buy latest version
| Buy XDate 1.0 license – $30.00 per developer. Includes full source code to XDateCalc.exe, XFisCal.exe, and XDateTest.exe. |