A relatively basic class designed to represent dates accurately over a very wide range, running from 4713BC to 9999AD, and handling the various calendar corrections, primarily the Julian/Gregorian changeover. It handles various kinds of date arithmetic efficiently, but conversions to and from more conventional month/day/year representations are more costly.
The class provides a default constructor that initializes the object to January 1, 4713BC, and a standard copy constructor. It provides 3 additional constructors as well. One initializes the object from a Unix time_t value, extracting the month, day and year of the time_t via the standard library routines and initializing the object to that date. Another initializes the object from a character string produced by the ToString() method, primarily for recreating objects stored in data files. The third takes the day, month and year in that order and initializes an object corresponding to that date.
A standard assignment operator is provided to assign one Date object to another correctly.
The complete set of relational operators is defined on pairs of Date objects. No comparisons to other types are defined.
Operators are defined to add longs to Dates, and to subtract longs from Dates. These operate by adding or subtracting the integer number of days to or from the Date object. Pre-increment and post-increment operators are defined analogous to the operators on integral types. The assignment addition and subtraction operators add and subtract the integral number of dates on the right side to or from the Date object on the left, eg. DateObject += 5; to add 5 days to a given date. Subtraction of two Date operators is defined, yielding the number of days between them as a long. Addition of two Date objects does not make sense and is not defined.
ToSysTime() takes no arguments and returns the date as a time_t value corresponding to midnight on the given date. ToString returns no value, it's argument is a pointer to a 12-byte character string which will be filled in with a string representation of the object. This may be passed to the char * constructor to recreate the object, and is a convenient representation for storage in a data file. There really ought to be a conversion operator to a character string, but it is rather difficult to handle the memory issues correctly.
These functions extract the obvious values from the date and return them to the program for use. Some non-obvious pointers:
The sole static function in the class is the IsLeapYear() function, which tests if the year passed as it's argument is a leap year or not. It returns non-zero if the year is a leap year, and zero if it is not.