home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / ZDATE.MAN < prev   
Text File  |  1997-07-05  |  48KB  |  1,074 lines

  1. +++Date last modified: 05-Jul-1997
  2.  
  3.              ZDATE - THE COMPLETE DATE MANIPULATION SOLUTION
  4.              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5.  
  6.            The zDate class (all code, manuals and examples) is
  7.              Copyright (c) 1995, 1996 Branislav L. Slantchev
  8.                          (CompuServe: 73023,262)
  9.  
  10.        THIS VERSION IS EXPLICITLY DONATED BY THE AUTHOR TO THE SNIPPETS
  11.        COLLECTION MAINTAINED BY BOB STOUT. YOU ARE ALLOWED TO USE THE
  12.        CODE FOR ANY PURPOSE (INCLUDING COMMERCIAL) FREE OF CHARGE AS
  13.        LONG AS YOU ACKNOWLEDGE IT. YOU ARE NOT ALLOWED TO REMOVE THE
  14.        COPYRIGHT NOTICES FROM THE CODE. YOU ARE FREE TO MAKE ANY
  15.        MODIFICATIONS NECESSARY TO SUIT YOUR NEEDS. I WILL APPRECIATE IF
  16.        YOU NOTIFY ME OF THESE CHANGES BUT THIS IS NOT A REQUIREMENT.
  17.        THERE ARE NO WARRANTIES, EITHER EXPRESS OR IMPLIED ABOUT THE
  18.        FITNESS OF THIS PRODUCT FOR ANY PARTICULAR PURPOSE. USE AT YOUR
  19.        OWN RISK. THE AUTHOR WILL BE IN NO WAY LIABLE FOR ANY USE, MISUSE
  20.        OR INABILITY TO USE OF THIS PRODUCT, AS WELL AS ANY LOSSES THAT
  21.        MIGHT HAVE OCCURRED AS RESULT OF THESE.
  22.  
  23. The zDate class provides your C++ programs with one of the most useful and
  24. easy to use date classes I have seen. It has been developed over a period of
  25. almost two years, with the functionality being refined to the point that the
  26. class interface is unobtrusive and intuitive. You won't have to worry about
  27. hidden assumptions, or side effects or oddly-named member functions.
  28. Everything is in plain sight. Having said that, let's look at some class
  29. specifics.
  30.  
  31. The zDate class is not meant to be used as a base class. You can, of course,
  32. but there's little point in doing it. There are no date formatting functions.
  33. I felt that these are fairly easy to find and the ANSI C library provides a
  34. very useful implementation in its strftime() function. There was simply no
  35. need to re-invent the wheel. The class, however, provides all the
  36. functionality you might need. Simple operators like comparison and assignment
  37. make the class as straightforward as can be. All the enumerated constants are
  38. encapsulated within the class to avoid namespace pollution. This class was
  39. written with the century roll-over in mind. It will work just fine after the
  40. year 2000 unlike many other implementations.
  41.  
  42. I should note here that the day numbering used internally (and retrievable
  43. via the DayNumber() function) is NOT the true Julian day scheme. This one
  44. begins at 1 A.D. unlike the Julian day numbers which go back 4000 years B.C.
  45. Effectively, this means that you cannot have dates which go into negative
  46. years, but I have yet to see this as a limitation worthy of a class re-
  47. design.
  48.  
  49. The class follows the general PB-Lib coding standards. For a complete
  50. reference, read the file Standard.Doc available with the library release.
  51. It should suffice to note that all member functions use mixed-case naming,
  52. with the first letters of each word capitalized. Functions that do not
  53. modify the class internals are declared as const. Functions that can be
  54. used without actually instantiating an object of the class are declared
  55. static. These can be used with the simple scope resolution operator without
  56. an object pointer. What follows is a complete class reference for all public
  57. data members and methods. Note that private and protected members and methods
  58. are not documented here. They are, however, fully explained with code
  59. comments.
  60.  
  61.  
  62.    ZDATE::MONTH
  63.    --------------------------------------------------------------------------
  64.      Synopsis   Enumeration type for the months of the year.
  65.  
  66.      Syntax     enum month { jan=1, feb, mar, apr, may, jun,
  67.                              jul, aug, sep, oct, nov, dec };
  68.  
  69.      Remarks    Use this enumeration to interpret the return values of
  70.                 various member functions. You should use the scope
  71.                 resolution operator to access them outside the class.
  72.  
  73.      Return     n/a
  74.  
  75.      See also   zDate::week_day; zDate::moon_phase
  76.  
  77.      Example    zDate::month myMonth = zDate::jul;
  78.                 if( zDate::aug == myMonth ) cout << "This can't be.";
  79.  
  80.  
  81.  
  82.    ZDATE::WEEK_DAY
  83.    --------------------------------------------------------------------------
  84.      Synopsis   Enumeration type for the different days of the week.
  85.  
  86.      Syntax     enum week_day { mon=1, tue, wed, thu, fri, sat, sun };
  87.  
  88.      Remarks    Use these enumerated constants to access the various day of
  89.                 week return values of functions. You must use the scope
  90.                 resolution operator to access them.
  91.  
  92.      Return     n/a
  93.  
  94.      See also   zDate::month; zDate::moon_phase
  95.  
  96.      Example    zDate::week_day wday = zDate::sun;
  97.                 switch( wday ){
  98.                     case zDate::sat:
  99.                     case zDate::sun:
  100.                         cout << "Oh, weekend! I love those" << endl;
  101.                     break;
  102.                    default: cout << "Another boring day!" << endl;
  103.                 }
  104.  
  105.  
  106.    ZDATE::MOON_PHASE
  107.    --------------------------------------------------------------------------
  108.      Synopsis  Enumeration constants to access the return value of the
  109.                MoonPhase routines.
  110.  
  111.      Syntax    enum moon_phase{ new_moon, waxing_crescent, first_quarter,
  112.                                 waxing_gibbous, full_moon, waning_gibbous,
  113.                                 third_quarter, waning_crescent };
  114.  
  115.      Remarks   Use these enumerated constants to interpret the return value
  116.                of the MoonPhase() member function. You should use the scope
  117.                resolution operator to access them.
  118.  
  119.      Return    n/a
  120.  
  121.      See also  zDate::MoonPhase; zDate::month; zDate::week_day
  122.  
  123.      Example   zDate::moon_phase phase = zDate::MoonPhase(zDate::Today());
  124.                switch( phase ){
  125.                    case zDate::full_moon:
  126.                        cout << "Grrrrr! The Werewolves are out!";
  127.                        break;
  128.                    default: cout << "Nothing yet!" << endl;
  129.                }
  130.  
  131.  
  132.    ZDATE::ZDATE
  133.    --------------------------------------------------------------------------
  134.      Synopsis  Various constructors to initialize the date objects.
  135.  
  136.      Syntax    zDate();
  137.                zDate(month aMonth, int aDay, int aYear);
  138.                zDate(int dayOfYear, int aYear);
  139.                zDate(const zDate &aDate);
  140.                zDate(ulong nDayNumber);
  141.                zDate(const struct tm *tmDate);
  142.  
  143.      Remarks   These constructors are used to initialize the date object in
  144.                various ways. The parameter names are self-explanatory.
  145.                Things you should know are that none of these constructors
  146.                will check the validity of the data being passed to it. You
  147.                must verify that all parameters are correct or the results
  148.                will be unpredictable. Years are specified in full (i.e. for
  149.                1996, you must pass 1996 as the aYear parameter, not 96 or
  150.                anything else). Years can go back to 1 A.D. You cannot use
  151.                negative years. The earliest date that is valid for the zDate
  152.                class is January 1, 0001. The 'dayOfYear' parameter must be
  153.                the number of the day for the 'aYear', starting with January 1
  154.                as day number 1. The 'nDayNumber' parameter is NOT the true
  155.                Julian day number of the day (these start some 4,000 years BC).
  156.                Rather, it's the day number with base of January 1, 0001 as
  157.                the 1st day. For the last constructor, the 'tmDate' parameter
  158.                must be correctly initialized as per its specifications (see
  159.                your compiler manual). With this format, the year is an
  160.                offset from 1900 (that is, 1996 is 96 and 2012 is 112). Also,
  161.                the month numbering scheme is different. These are all taken
  162.                care of in the zDate constructor itself. Finally, the copy
  163.                constructor will initialize the current zDate object with the
  164.                value of another one.
  165.  
  166.      Return    n/a
  167.  
  168.      See also  zDate::Today(); zDate::EndDST(); zDate::BeginDST()
  169.  
  170.      Example   // here are examples of all possible ways of initialization
  171.                zDate date1;                       // January 1, 0001
  172.                zDate date2(zDate::jul, 16, 1973); // July 16, 1973
  173.                zDate date3(15, 1995);             // January 15, 1995
  174.                zDate date4(date2);                // same as date2
  175.                zDate date5(728945L);              // October 11, 1996
  176.                time_t secs = time(0);             // current time/date
  177.                zDate date6( localtime(&secs) );   // (use struct tm*)
  178.                zDate date7(zDate::Today());       // current date
  179.  
  180.  
  181.    ZDATE::ADDMONTHS
  182.    --------------------------------------------------------------------------
  183.      Synopsis  Adds or subtracts months from the date object.
  184.  
  185.      Syntax    zDate AddMonths(int nMonths) const;
  186.  
  187.      Remarks   This member function will add or subtract (if 'nMonths' is
  188.                negative) the number of months to the current date object and
  189.                will return another zDate object with the new values. It does
  190.                not modify the current object. This will adjust the number of
  191.                years if necessary. Note that month arithmetic is fairly
  192.                straightforward as only the month will be changed regardless
  193.                of the days in each month. However, this may cause some
  194.                invalid dates (such as July 31 minus 5 months is February 31,
  195.                which is clearly invalid). The function will adjust the day
  196.                of the month in that case according to the following rules:
  197.                if adding months, the month will roll over into the next one
  198.                (causing a year increase, if necessary) and the new day number
  199.                will be the overflow (i.e. April 31 will become May 1). If
  200.                subtracting, the overflow is subtracted from the current day
  201.                number (i.e. in the example with February, the new day will
  202.                be 27 or 26, depending on whether the year is leap or not).
  203.                Care must be taken when subtracting months not to cause the
  204.                year to become less that 1 A.D.
  205.  
  206.      Return    A zDate object with the new date value.
  207.  
  208.      See also  zDate::AddYears(); zDate::AddWeeks(); zDate::operator+();
  209.  
  210.      Example   zDate ind(zDate::jul, 4, 1776);
  211.                assert(ind.AddMonths(2400)==zDate(zDate::jul,4,1996));
  212.  
  213.  
  214.    ZDATE::ADDWEEKS
  215.    --------------------------------------------------------------------------
  216.      Synopsis  Adds or subtracts a number of weeks from the date object.
  217.  
  218.      Syntax    zDate AddWeeks(int nWeeks) const;
  219.  
  220.      Remarks   This member function will add or subtract (if 'nWeeks' is
  221.                negative) the number of weeks from the current date object
  222.                and will return a new zDate object with the resulting value.
  223.                It does not modify the calling object. There are no fancy
  224.                calculations with this function, it simply uses weeks as
  225.                spans of 7 days and actually adds/subtracts days. This will
  226.                modify the year and the month, as well as the day as necessary.
  227.                Care must be taken that the year does not become less than
  228.                1 A.D.
  229.  
  230.      Return    A zDate object with the new date value.
  231.  
  232.      See also  zDate::AddYears(); zDate::AddMonths(); zDate::operator+();
  233.  
  234.      Example   zDate date(zDate::oct, 11, 1996);
  235.                assert(date.AddWeeks(-1) == zDate(zDate::oct,4,1996));
  236.  
  237.  
  238.    ZDATE::ADDYEARS
  239.    --------------------------------------------------------------------------
  240.      Synopsis  Adds or subtracts a number of years from a date.
  241.  
  242.      Syntax    zDate AddYears(int nYears) const;
  243.  
  244.      Remarks   This member function will add or subtract (if 'nYears' is
  245.                negative) a number of years to the current date object and
  246.                will return a new zDate with the resulting value. The calling
  247.                object is not modified by this function. Note that when
  248.                manipulating years, a date could become invalidated (such as
  249.                adding 1 to a leap year will cause February 29 to be an
  250.                invalid date). This routine takes that into account and will
  251.                adjust itself accordingly (in the example above, the new date
  252.                will be March 1). Care must be taken that years do not fall
  253.                below 1 A.D.
  254.  
  255.      Return    A zDate object with the new date.
  256.  
  257.      See also  zDate::AddWeeks(); zDate::AddMonths(); zDate::operator+();
  258.  
  259.      Example   zDate date(zDate::feb, 29, 1996);
  260.                assert(date.AddYears(-2) == zDate(zDate::mar,1,1994));
  261.  
  262.  
  263.    ZDATE::AGE
  264.    --------------------------------------------------------------------------
  265.      Synopsis  Returns the age of someone with a specific birthrate
  266.                (for current date object).
  267.  
  268.      Syntax    int Age(const zDate &BirthDay) const;
  269.  
  270.      Remarks   This routine calculates the age of a person with a birthday
  271.                date of 'BirthDay'. This function does not modify the calling
  272.                object. Care must be taken that the calling object is greater
  273.                than BirthDay (i.e. that the person has already been born).
  274.  
  275.      Return    The age (in years) of the person.
  276.  
  277.      See also  zDate::operator-()
  278.  
  279.      Example   zDate brani(zDate::jul, 16, 1973);
  280.                cout << "I am " << Today().Age(brani) << " years old";
  281.  
  282.  
  283.    ZDATE::BEGINDST
  284.    --------------------------------------------------------------------------
  285.      Synopsis  Calculates the beginning date of the Daylight Savings Time.
  286.  
  287.      Syntax    zDate BeginDST() const;
  288.                static zDate BeginDST(int aYear);
  289.  
  290.      Remarks   There are two version of this function. The first one returns
  291.                the date of the beginning of DST for the year of the current
  292.                date object. The second one is more generic as it returns the
  293.                start of DST for any year. These routine do not modify
  294.                anything, they simply return a zDate object with the date
  295.                when the DST comes into effect. By default, the routines will
  296.                use the USA standard for DST calculations. In the US, DST
  297.                begins at 2:00am on the first Sunday of April and ends at
  298.                2:00am on the last Sunday of October. You can modify these
  299.                rules by using the SetBeginDST() and SetEndDST() member
  300.                functions.
  301.  
  302.      Return    The date when DST will come into effect.
  303.  
  304.      See also  zDate::EndDST(); zDate::IsDST(); zDate::SetBeginDST()
  305.  
  306.      Example   assert(zDate::BeginDST(1996)==zDate(zDate::apr,7,1996))
  307.  
  308.  
  309.    ZDATE::DAY
  310.    --------------------------------------------------------------------------
  311.      Synopsis  Returns the day of month of the current date object.
  312.  
  313.      Syntax    int Day() const;
  314.  
  315.      Remarks   This routine return the current day of the month. Days start
  316.                from 1 and can go up to 31, depending on the current day.
  317.                Note that there are no days between October 4 and October 15,
  318.                1582 (this is when Pope Gregor XIII canceled them).
  319.  
  320.      Return    The day of the month.
  321.  
  322.      See also  zDate::Month(); zDate::Year(); zDate::DayOfWeek();
  323.  
  324.      Example   cout << "Today is the " << zDate::Today().Day()
  325.                     << "th day of the month";
  326.  
  327.  
  328.    ZDATE::DAYNUMBER
  329.    --------------------------------------------------------------------------
  330.      Synopsis  Returns the day number (from January 1, 1) for the object.
  331.  
  332.      Syntax    ulong DayNumber() const;
  333.  
  334.      Remarks   This returns the day number of the date object. Day numbering
  335.                begins with January 1, 0001 A.D. being day 1 and so on. As
  336.                such, these day numbers are not Julian dates (which begin
  337.                several thousand years B.C.). Leap years are taken into
  338.                account as well as the Gregorian reform (with the standard
  339.                date of October 4, 1582)
  340.  
  341.      Return    The day number (unsigned long integer).
  342.  
  343.      See also  zDate::zDate(ulong nDayNumber);
  344.  
  345.      Example   cout << "Today is the " << zDate::Today().DayNumber()
  346.                     << "th day of the year.";
  347.  
  348.  
  349.    ZDATE::DAYOFWEEK
  350.    --------------------------------------------------------------------------
  351.      Synopsis  Returns the day of the week for the date object.
  352.  
  353.      Syntax    week_day DayOfWeek() const;
  354.  
  355.      Remarks   This returns the day of the week for the current date object.
  356.                You must use the week_day enumeration to interpret the return
  357.                value of this function. When trying to access the week_day
  358.                constants, be sure to use the scope resolution operator.
  359.  
  360.      Return    The day of the week.
  361.  
  362.      See also  zDate::week_day;
  363.  
  364.      Example   assert(zDate::sat == zDate(zDate::oct,5,1996).DayOfWeek());
  365.  
  366.  
  367.    ZDATE::DAYOFYEAR
  368.    --------------------------------------------------------------------------
  369.      Synopsis  Returns the day of the year from January 1.
  370.  
  371.      Syntax    int DayOfYear() const;
  372.  
  373.      Remarks   This member function returns the day of the year for the
  374.                current object. The day numbering starts from January 1 for
  375.                the same year being the first day. The current day number
  376.                will depend on whether the year is leap or not too. The range
  377.                of possible values is 1..366 (or 365 for non-leap years),
  378.                with the upper limit being December 31.
  379.  
  380.      Return    The day number.
  381.  
  382.      See also  zDate::DayOfWeek(); zDate::DayNumber();
  383.  
  384.      Example   assert(366 == zDate(zDate::dec,31,2000).DayOfYear());
  385.  
  386.  
  387.    ZDATE::DAYSINMONTH
  388.    --------------------------------------------------------------------------
  389.      Synopsis  Returns the number of days for a specific month in a year.
  390.  
  391.      Syntax           int DaysInMonth() const;
  392.                static int DaysInMonth(month aMonth, int aYear);
  393.  
  394.      Remarks   These two versions of the function will return the number of
  395.                days for a specific month. The first version will return the
  396.                number of days in the month of the date object that called it;
  397.                while the second version can be used without an actual zDate
  398.                object and returns the number of days for a month of a year
  399.                you specify. Note that October 1582 had only 21 days as a
  400.                result of the reform of Pope Gregor XIII.
  401.  
  402.      Return    The number of days in a month.
  403.  
  404.      See also  zDate::DaysInYear(); zDate::IsLeapYear();
  405.  
  406.      Example   assert( 28 == zDate::DaysInMonth(zDate::feb, 1995) );
  407.  
  408.  
  409.    ZDATE::DAYSINYEAR
  410.    --------------------------------------------------------------------------
  411.      Synopsis  Returns the number of days in a specific year.
  412.  
  413.      Syntax           int DaysInYear() const;
  414.                static int DaysInYear(int aYear);
  415.  
  416.      Remarks   The first version of this routine returns the number of days
  417.                in the year of the current date object. The second version
  418.                can be used without instantiating an actual object and returns
  419.                the number of days in any year. There are two possible values
  420.                365 and 366 depending on whether the year is leap or not
  421.                (except for 1582 which lost 10 days). These functions do not
  422.                modify any objects.
  423.  
  424.      Return    The number of days in a year.
  425.  
  426.      See also  zDate::DaysInMonth(); zDate::IsLeapYear();
  427.  
  428.      Example   assert( 366 == zDate::DaysInYear(1996) );
  429.  
  430.  
  431.    ZDATE::EASTER
  432.    --------------------------------------------------------------------------
  433.      Synopsis  Return the date of Easter for any given year.
  434.  
  435.      Syntax           zDate Easter() const;
  436.                static zDate Easter(int year);
  437.  
  438.      Remarks   This routine returns the date for Easter for any given year
  439.                (the second version) or for the year of the calling zDate
  440.                object. It uses some obscure algorithm to calculate the
  441.                ecclesiastical Easter (which is the same for all countries
  442.                regardless of where they are) and is different from the
  443.                astronomical date (which does not mean much anyway). Easter is
  444.                sometimes said to be the first Sunday that occurs after the
  445.                full moon that follows the vernal equinox (March 22). This
  446.                means the Easter can vary between March 22 and April 25. This
  447.                is an over-simplification as the Church does not actually use
  448.                astronomical observations of the Moon but rather, it has
  449.                constructed its own calendar of Easter days which it uses.
  450.                This function is a very presentable approximation. For more
  451.                information, read one of the Almanacs or visit the US Naval
  452.                Observatory. They have tons of nice information there,
  453.                including an even more obfuscated formula for calculating the
  454.                Easter date.
  455.  
  456.      Return    A zDate object with the Easter date.
  457.  
  458.      See also  zDate::MoonPhase(); zDate::DayOfWeek()
  459.  
  460.      Example   zDate Easter(zDate::apr, 7, 1996);
  461.                assert( Easter == zDate::Easter(1996) );
  462.  
  463.  
  464.    ZDATE::ENDDST
  465.    --------------------------------------------------------------------------
  466.      Synopsis  Return the date when the Daylight Savings Time is ended.
  467.  
  468.      Syntax           zDate EndDST() const;
  469.                static zDate EndDST(int aYear);
  470.  
  471.      Remarks   This function is similar to BeginDST() except it returns the
  472.                date when the Daylight Savings Time stops being in effect.
  473.                The default uses the American convention of ending DST at
  474.                2:00am on the last Sunday of October. This behavior can be
  475.                modified to suit your specific locale.
  476.  
  477.      Return    A zDate object with the correct date.
  478.  
  479.      See also  zDate::IsDST(); zDate::SetEndDST(); zDate::BeginDST();
  480.  
  481.      Example   assert(zDate(zDate::oct,27,1996) == zDate::EndDST(1996));
  482.  
  483.  
  484.    ZDATE::ISDST
  485.    --------------------------------------------------------------------------
  486.      Synopsis  Checks if a date falls in the Daylight Savings Time range.
  487.  
  488.      Syntax           Boolean IsDST() const;
  489.                static Boolean IsDST(const zDate &aDate);
  490.  
  491.      Remarks   This function checks if a date happens to be in the period
  492.                during which Daylight Savings Time is in effect. The default
  493.                uses the US convention which begins DST on the first Sunday of
  494.                April and ends it on the last Sunday of October. You can
  495.                modify the time span of the DST period with the SetBeginDST()
  496.                and SetEndDST() functions. The second version is more generic
  497.                and will check any date object (the first one is intended to
  498.                be called via an object to check itself).
  499.  
  500.      Return    True, if the date falls in the DST period range;
  501.                False, otherwise.
  502.  
  503.      See also  zDate::SetBeginDST(); zDate::SetEndDST)();
  504.  
  505.      Example   assert( zDate(zDate::jul, 16, 1996).IsDST() );
  506.  
  507.  
  508.    ZDATE::ISLEAPYEAR
  509.    --------------------------------------------------------------------------
  510.      Synopsis  Checks if a specific year is leap.
  511.  
  512.      Syntax           Boolean IsLeapYear() const;
  513.                static Boolean IsLeapYear(int aYear);
  514.  
  515.      Remarks   This routine checks if a year is leap or not. Leap years are
  516.                defined as follows: before the Gregorian reform, any year
  517.                divisible by 4 is a leap year. After the reform, all years
  518.                divisible by 4 are leap years unless they are also divisible
  519.                by 100 and not divisible by 400 (that means that 1500 was not
  520.                a leap year but 1600 was). The second version can be called
  521.                without a zDate object to check any year.
  522.  
  523.      Return    True if the year is leap; False otherwise.
  524.  
  525.      See also  zDate::DayNumber();
  526.  
  527.      Example   assert(True == zDate::IsLeapYear(1600));
  528.                assert(False == zDate(zDate::jan,1,1500).IsLeapYear());
  529.  
  530.  
  531.    ZDATE::ISVALID
  532.    --------------------------------------------------------------------------
  533.      Synopsis  Checks if a date is valid.
  534.  
  535.      Syntax           Boolean IsValid() const;
  536.                static Boolean IsValid(month Month, int Day, int Year);
  537.  
  538.      Remarks   Checks if all the fields of a particular date are valid. Note
  539.                that this function is not called within the class member
  540.                routines. They all assume they are dealing with valid dates.
  541.                It is your responsibility to ensure that. A valid date is any
  542.                date after January 1, 0001 (with the exception of the days
  543.                between October 4 and 15, 1582). Also checked are the day of
  544.                month (this has to be correct for the current month). Note
  545.                that you can use the second version without an actual zDate
  546.                object to check any date.
  547.  
  548.      Return    True if the date is valid, False otherwise.
  549.  
  550.      See also  n/a
  551.  
  552.      Example   assert( !zDate(zDate::feb, 31, 1996).IsValid );
  553.  
  554.  
  555.    ZDATE::MONTH
  556.    --------------------------------------------------------------------------
  557.      Synopsis  Returns the month of the date object.
  558.  
  559.      Syntax    zDate::month Month() const;
  560.  
  561.      Remarks   This routine returns the month of the current date object.
  562.                The return value can be examined via the zDate::month
  563.                enumeration constants. You will need to use the scope
  564.                resolution operator to access those.
  565.  
  566.      Return    The month of the year.
  567.  
  568.      See also  zDate::Year(); zDate::Day();
  569.  
  570.      Example   switch( zDate::Today().Month() ){
  571.                    case zDate::jul:
  572.                        cout << "This is my month!";
  573.                        break;
  574.                     default:
  575.                        cout << "Just another month";
  576.                        break
  577.                }
  578.  
  579.  
  580.    ZDATE::MOONPHASE
  581.    --------------------------------------------------------------------------
  582.      Synopsis  Determines the phase of the moon.
  583.  
  584.      Syntax           zDate::moon_phase MoonPhase() const;
  585.                static zDate::moon_phase MoonPhase(const zDate &aDate);
  586.  
  587.      Remarks   This routine determines the phase of the moon for a given
  588.                date. You need to use the supplied enumeration constants
  589.                'moon_phase' to interpret the result. The Moon moves through
  590.                8 phases on its way around the earth during the Moon cycle
  591.                which lasts about 30 days. Whenever the moon is between the
  592.                Earth and the Sun, we have a new moon (i.e. the Moon is not
  593.                visible in the sky). Then the Moon's visible surface starts
  594.                increasing and it moves through the waxing crescent, first
  595.                quarter, and waxing gibbous stages to the full moon position
  596.                (when the Earth is between the Moon and the Sun). From that
  597.                point on, the visible surface of the Moon decreases going
  598.                from waning gibbous, through the third quarter, and to a
  599.                waning crescent. Then the cycle repeats. You can use the
  600.                second version of the function to calculate the moon phase
  601.                for any date object.
  602.  
  603.      Return    The phase of the Moon.
  604.  
  605.      See also  zDate::moon_phase
  606.  
  607.      Example   zDate fullMoon(zDate::sep, 26, 1996);
  608.                assert( zDate::full_moon == fullMoon.MoonPhase() );
  609.  
  610.  
  611.    ZDATE::OPERATOR LONG
  612.    --------------------------------------------------------------------------
  613.      Synopsis  Type cast of a zDate to a long integer, return the day number.
  614.  
  615.      Syntax    operator long() const;
  616.  
  617.      Remarks   This operator is useful for a type cast in situations where
  618.                you need a long number representation of the date. The same
  619.                effect can be achieved with the DayNumber() functions as the
  620.                results are identical. This may be a cleaner solution for some
  621.                situations (like passing the day number to a function which
  622.                expects a long, in which case you can specify the zDate
  623.                object as a parameter and the cast will be performed
  624.                automatically).
  625.  
  626.      Return    The day number from January 1, 0001 A.D.
  627.  
  628.      See also  zDate::DayNumber();
  629.  
  630.      Example   // this is a contrived example which forces the use
  631.                // of the zDate(ulong nDayNumber) constructor instead
  632.                // of the copy constructor. Generally, you don't want
  633.                // to do this, as the latter is a lot faster!
  634.                ZDate date( (long)zDate::Today() );
  635.  
  636.  
  637.    ZDATE::OPERATOR!=
  638.    --------------------------------------------------------------------------
  639.      Synopsis  Tests two dates for inequality.
  640.  
  641.      Syntax    Boolean operator!=(const zDate &aDate) const;
  642.  
  643.      Remarks   This operator allows intuitive test for date inequality.
  644.                You can test if two dates are different using the regular
  645.                C++ notation.
  646.  
  647.      Return    True if dates are different, False if they are the same.
  648.  
  649.      See also  zDate::operator==();
  650.  
  651.      Example   zDate first(zDate::jul, 16, 1973);
  652.                zDate second = zDate::Today();
  653.                assert( first != second );
  654.  
  655.  
  656.    ZDATE::OPERATOR+
  657.    --------------------------------------------------------------------------
  658.      Synopsis  Adds or subtracts a number of days from a date object.
  659.  
  660.      Syntax    zDate operator+(int nDays) const;
  661.                zDate operator+(long nDays) const;
  662.  
  663.      Remarks   This operator allows adding a number of days to a date object
  664.                or subtracting (if the 'nDays' parameter is negative) a
  665.                certain amount of days. Care should be taken that the
  666.                resulting year does not fall below 1 A.D. The current date
  667.                object is not modified, which is what is to be expected with
  668.                the standard C++ behavior.
  669.  
  670.      Return    A zDate object with the new date value.
  671.  
  672.      See also  zDate::operator+=(); zDate::operator++(0
  673.  
  674.      Example   zDate date1(zDate::oct, 3, 1996);
  675.                zDate date2 = date1 + 55;
  676.                assert( date2 == zDate(zDate::nov, 27, 1996) );
  677.  
  678.  
  679.    ZDATE::OPERATOR++
  680.    --------------------------------------------------------------------------
  681.      Synopsis  Increments the date object by 1 day.
  682.  
  683.      Syntax    zDate operator++();
  684.                zDate operator++(int);
  685.  
  686.      Remarks   This is a simple increment operator which will increase the
  687.                current date object by 1 day. Note that both prefix and
  688.                postfix versions are supported. These behave in the standard
  689.                C++ way (i.e. the prefix version will cause the date object
  690.                to be modified and then the new value returned, while the
  691.                postfix version will cause the date object to be modified,
  692.                but its old value will be returned).
  693.  
  694.      Return    Prefix version returns incremented value of object;
  695.                Postfix version returns the value of the object before
  696.                the modification.
  697.  
  698.      See also  zDate::operator+=(); zDate::operatorù();
  699.  
  700.      Example   zDate date(zDate::jan, 1, 1996);
  701.                assert( zDate(zDate::jan, 1, 1996) == date++ );
  702.                assert( zDate(zDate::jan, 3, 1996) == ++date );
  703.  
  704.  
  705.    ZDATE::OPERATOR+=
  706.    --------------------------------------------------------------------------
  707.      Synopsis  Adds a number of days to a date object and modifies it.
  708.  
  709.      Syntax    zDate& operator+=(int nDays);
  710.                zDate& operator+=(long nDays);
  711.  
  712.      Remarks   This operator behaves just like the regular C++ counterpart.
  713.                It will add the number of days in 'nDays' (which can be
  714.                negative too) to the current object and will modify it. It
  715.                also returns a reference to this object so chaining is
  716.                allowed.
  717.  
  718.      Return    A reference to the modified object.
  719.  
  720.      See also  zDate::operator+(); zDate::operator-=();
  721.  
  722.      Example   zDate date(zDate::oct, 4, 1996);
  723.                date += 217;
  724.                assert( date == zDate(zDate::sep, 5, 1997) );
  725.  
  726.  
  727.    ZDATE::OPERATOR-
  728.    --------------------------------------------------------------------------
  729.      Synopsis  Subtracts days from a date object.
  730.                Finds difference between two dates.
  731.  
  732.      Syntax    long operator-(const zDate &aDate) const;
  733.                zDate operator-(int nDays) const;
  734.                zDate operator-(long nDays) const;
  735.  
  736.      Remarks   There are two distinct versions of this operator. The first
  737.                one is used to find the difference (in days) between two date
  738.                objects. The other version is used for subtracting a certain
  739.                number of days from a date object (or adding, of course, if
  740.                the 'nDays' parameter is negative). Care should be taken that
  741.                the resulting year is not smaller than 1 A.D.
  742.  
  743.      Return    The first version returns a long integer with the difference
  744.                (in days) between the two dates. This can be either negative
  745.                or positive or 0.
  746.                The second version returns a zDate object which contains the
  747.                resulting value.
  748.  
  749.      See also  zDate::operatorù(); zDate::operator-=();
  750.  
  751.      Example   zDate date1(zDate::jul, 4, 1776);
  752.                // this is the first version: difference in days
  753.                long days = zDate::Today() - date1;
  754.                cout << "There have been " << days
  755.                     << " days since Independence Day.";
  756.                // this is the second version: subtracting days
  757.                assert( date1 + days == zDate::Today() );
  758.  
  759.  
  760.    ZDATE::OPERATOR--
  761.    --------------------------------------------------------------------------
  762.      Synopsis  Decrements the date object value by 1 day.
  763.  
  764.      Syntax    zDate operator--();
  765.                zDate operator--(int);
  766.  
  767.      Remarks   These are the decrement operators. They work exactly like
  768.                their C++ counterparts. Both the prefix and postfix versions
  769.                are supported. The prefix version will first modify the date
  770.                and then return the new value. The postfix will modify the
  771.                date and return the old value.
  772.  
  773.      Return    Prefix version returns new value of date;
  774.                Postfix version returns the old value of date.
  775.  
  776.      See also  zDate::operator-(); zDate::operator-=();
  777.  
  778.      Example   zDate date(zDate::oct, 5, 1996);
  779.                // test the postfix version (same value returned)
  780.                assert( zDate(zDate::oct, 5, 1996) == date-- );
  781.                // test the prefix version, new value returned
  782.                // note that date is already Oct 4, 1996 from above
  783.                assert( zDate(zDate::oct, 3, 1996) == --date );
  784.  
  785.  
  786.    ZDATE::OPERATOR-=
  787.    --------------------------------------------------------------------------
  788.      Synopsis  Subtracts a number of days from an object and modifies it.
  789.  
  790.      Syntax    zDate& operator-=(int nDays);
  791.                zDate& operator-=(long nDays);
  792.  
  793.      Remarks   This operator subtracts 'nDays' days from the current object
  794.                and assigns the new value to it (or adds the days if the
  795.                'nDays' parameter is negative). Care must be taken so that
  796.                the resulting year is not smaller than 1 A.D. A reference to
  797.                the modified object is return to allow chaining.
  798.  
  799.      Return    Reference to the modified object.
  800.  
  801.      See also  zDate::operator+=(); zDate::operatorù();
  802.  
  803.      Example   zDate date(zDate::oct, 4, 1996);
  804.                date -= -217;
  805.                assert( date == zDate(zDate::sep, 5, 1997) );
  806.  
  807.  
  808.    ZDATE::OPERATOR<, OPERATOR<=, OPERATOR>, OPERATOR>=
  809.    --------------------------------------------------------------------------
  810.      Synopsis  Operators to compare two dates.
  811.  
  812.      Syntax    Boolean operator> (const zDate &date2) const;
  813.                Boolean operator>=(const zDate &date2) const;
  814.                Boolean operator< (const zDate &date2) const;
  815.                Boolean operator<=(const zDate &date2) const;
  816.  
  817.      Remarks   These operators allow intuitive comparisons of two date
  818.                objects. They behave similarly to their C++ counterparts. A
  819.                date is considered "smaller" than another if it specifies an
  820.                earlier point in time (that is, July 16, 1973 is "smaller"
  821.                than July 16, 1996).
  822.  
  823.      Return    True if the comparison reflects the relative dates;
  824.                False otherwise.
  825.  
  826.      See also  zDate::operator==(); zDate::operator!=();
  827.  
  828.      Example   zDate date1 = zDate::Today();
  829.                assert( date1 >  zDate(zDate::jan, 1, 1800) );
  830.                assert( date1 >= zDate::Today() );
  831.                assert( date1 <  zDate(zDate::jan, 1, 2200) );
  832.                assert( date1 <= zDate::Today() );
  833.  
  834.  
  835.    ZDATE::OPERATOR=
  836.    --------------------------------------------------------------------------
  837.      Synopsis  Operator that assigns one date object to another.
  838.  
  839.      Syntax    zDate& operator=(const zDate &aNewDate);
  840.  
  841.      Remarks   This operator allows assigning one date to another using the
  842.                usual C++ syntax. A reference to the modified object is
  843.                returned to allow proper chaining.
  844.  
  845.      Return    A reference to the current object with the new value.
  846.  
  847.      See also  zDate::zDate();
  848.  
  849.      Example   // date1 initialized via the copy constructor
  850.                zDate date1(zDate::Today());
  851.                // date2 initialized via the assignment operator
  852.                zDate date2 = zDate::Today();
  853.                assert( date1 == date2 );
  854.  
  855.  
  856.    ZDATE::OPERATOR==
  857.    --------------------------------------------------------------------------
  858.      Synopsis  Tests two dates for equality.
  859.  
  860.      Syntax    Boolean operator==(const zDate &aDate) const;
  861.  
  862.      Remarks   Tests if the current day object contains the same date as
  863.                the 'aDate' parameter. This allows for intuitive test in the
  864.                usual C++ way.
  865.  
  866.      Return    True if the dates are the same; False otherwise.
  867.  
  868.      See also  zDate::operator!=();
  869.  
  870.      Example   zDate date1 = zDate::Today();
  871.                assert( date1 == zDate::Today() );
  872.  
  873.  
  874.    ZDATE::OPERATOR[]
  875.    --------------------------------------------------------------------------
  876.      Synopsis  Return date information with array-like syntax.
  877.  
  878.      Syntax    char operator[](int index) const;
  879.  
  880.      Remarks   This arguably useful routine is of special interest to
  881.                ProBoard programmers. It can be used to get values in
  882.                DateType-compatible format (as used by ProBoard's SDK). The
  883.                only valid 'index' values are 0, 1, or 2. Anything else will
  884.                result in '-1' being returned. Index of 0 specifies that the
  885.                day is to be returned (1..31); index value of 1 specifies
  886.                that the month is to be returned (1..12); index value of 2
  887.                specifies that the year is to be returned in struct
  888.                tm-compatible format (i.e. 1996 is returned as 96).
  889.  
  890.      Return    Date information in DateType compatible format.
  891.  
  892.      See also  zDate::Day(); zDate::Month(); zDate::Year();
  893.  
  894.      Example   zDate date(zDate::jul, 16, 1973);
  895.                // this will print 16/7/73
  896.                cout << date[0] << "/" << date[1] << "/" << date[2];
  897.  
  898.  
  899.    ZDATE::SETBEGINDST
  900.    --------------------------------------------------------------------------
  901.      Synopsis  Sets the beginning of Daylight Savings Time for the class.
  902.  
  903.      Syntax    static void SetBeginDST(month aMon, week_day aWeekDay);
  904.  
  905.      Remarks   Since the class defaults to the US convention of specifying
  906.                DST to begin on the first Sunday of April, it might be useful
  907.                to specify an alternative starting point. Note that the
  908.                'aWeekDay' is assumed to be the first one in the month. This
  909.                will set the internal values of the DST starting date.
  910.  
  911.      Return    Nothing.
  912.  
  913.      See also  zDate::SetEndDST(); zDate::IsDST(); zDate::BeginDST();
  914.  
  915.      Example   // set the DST to begin on first Monday of March
  916.                zDate::SetBeginDST(zDate::mar, zDate::mon);
  917.  
  918.  
  919.    ZDATE::SETENDDST
  920.    --------------------------------------------------------------------------
  921.      Synopsis  Sets the ending of the Daylight Savings Time for the class.
  922.  
  923.      Syntax    static void SetEndDST(month aMonth, week_day aWeekDay);
  924.  
  925.      Remarks   Since the class defaults to the US convention of specifying
  926.                DST to end on the last Sunday of October, it might be useful
  927.                to specify an alternative ending point. Note that the
  928.                'aWeekDay' parameter is assumed to be the last occurrence of
  929.                this week day in the month. This will set the internal values
  930.                of the DST ending date.
  931.  
  932.      Return    Nothing.
  933.  
  934.      See also  zDate::SetBeginDST(); zDate::IsDST(); zDate::EndDST();
  935.  
  936.      Example   // set the DST to end on the last Monday of November
  937.                zDate::SetEndDST(zDate::nov, zDate::mon);
  938.  
  939.  
  940.    ZDATE::TODAY
  941.    --------------------------------------------------------------------------
  942.      Synopsis  Returns a zDate object with today's date.
  943.  
  944.      Syntax    static zDate Today();
  945.  
  946.      Remarks   This is a very useful member function which returns a zDate
  947.                object that reflects the current system date. It can be used
  948.                without an actual instance of zDate (because it is static)
  949.                and can be passed to zDate constructors to set date objects
  950.                to the current date.
  951.  
  952.      Return    A zDate object with the current system date.
  953.  
  954.      See also  zDate::zDate();
  955.  
  956.      Example   // two ways to init objects to current date
  957.                zDate date1(zDate::Today());
  958.                zDate date2 = zDate::Today();
  959.                assert( date1 == date2 );
  960.  
  961.  
  962.    ZDATE::WEEKOFMONTH
  963.    --------------------------------------------------------------------------
  964.      Synopsis  Returns the week of the month the current day is in.
  965.  
  966.      Syntax    int WeekOfMonth() const;
  967.  
  968.      Remarks   This routine returns the number of the week the current day
  969.                is in. Weeks start from 1 each month.
  970.  
  971.      Return    The week number.
  972.  
  973.      See also  zDate::WeekOfYear(); zDate::WeeksInYear();
  974.  
  975.      Example   // October 17, 1996 is in the 3rd week of October
  976.                assert(3 == zDate(zDate::oct,17,1996).WeekOfMonth());
  977.  
  978.  
  979.    ZDATE::WEEKOFYEAR
  980.    --------------------------------------------------------------------------
  981.      Synopsis  Returns the week of the year the current date is in.
  982.  
  983.      Syntax    int WeekOfYear() const;
  984.  
  985.      Remarks   This routine returns the number of the week the current date
  986.                is in. Weeks start from 1 at the beginning of the year.
  987.  
  988.      Return    The week number.
  989.  
  990.      See also  zDate::WeekOfMonth(); zDate::WeeksInYear();
  991.  
  992.      Example   // October 11, 1996 is in the 41st week of the year
  993.                zDate date(zDate::oct, 11, 1996);
  994.                assert( 41 == date.WeekOfYear() );
  995.  
  996.  
  997.    ZDATE::WEEKSINYEAR
  998.    --------------------------------------------------------------------------
  999.      Synopsis  Returns the number of weeks in the year.
  1000.  
  1001.      Syntax           int WeeksInYear() const;
  1002.                static int WeeksInYear(int aYear);
  1003.  
  1004.      Remarks   This routine returns the number of weeks for a particular
  1005.                year. The first version uses the current object's year, while
  1006.                the second one works for any year (of course, the year must
  1007.                be greater than 1 A.D., as usual). Note that this routine
  1008.                simply calculates the number of week that December 31 for the
  1009.                specified year falls in. This may or may not mean that there
  1010.                were that many weeks exactly.
  1011.  
  1012.      Return    The number of weeks.
  1013.  
  1014.      See also  zDate::WeekOfYear(); zDate::WeekOfMonth();
  1015.  
  1016.      Example   // 1996 has 53 weeks in it
  1017.                assert( 53 == zDate::WeeksInYear(1996) );
  1018.  
  1019.  
  1020.    ZDATE::YEAR
  1021.    --------------------------------------------------------------------------
  1022.      Synopsis  Returns the year of the current object.
  1023.  
  1024.      Syntax    int Year() const;
  1025.  
  1026.      Remarks   This routine returns the year of the current date object.
  1027.                Valid years start with 1 A.D. The return value is the 4-digit
  1028.                full representation of the year (that is, for 1996, this
  1029.                routine will return 1996, and not just 96).
  1030.  
  1031.      Return    The year.
  1032.  
  1033.      See also  zDate::Day(); zDate::Month();
  1034.  
  1035.      Example   zDate date(zDate::oct, 14, 1996);
  1036.                assert( 1996 == date.Year() );
  1037.  
  1038.  
  1039.    ZDATE::REFORMMONTH, ZDATE::REFORMYEAR, ZDATE::REFORMDAYNUMBER
  1040.    --------------------------------------------------------------------------
  1041.      Synopsis  Month, year and day of Pope Gregor's XIII calendar reform.
  1042.  
  1043.      Syntax    static const int   ReformYear;
  1044.                static const month ReformMonth;
  1045.                static const ulong ReformDayNumber;
  1046.  
  1047.      Remarks   These publicly accessible constants reflect the year (1582),
  1048.                the month (October), and the day number (577737L, by
  1049.                convention) of the calendar reform instituted by Pope Gregor
  1050.                XIII. This happened on October 4, 1582 when the pope canceled
  1051.                10 days of this month, so the next day became October 15
  1052.                instead of October 5. This was done because it was discovered
  1053.                that the Julian calendar used up to this point incorrectly
  1054.                divided the year in 365.25 days. By 1582, the error was so
  1055.                big that the church had problems with the Easter and
  1056.                Christmas which fell during some weird seasons. The pope also
  1057.                changed the method of calculation of leap years. Before him,
  1058.                a leap year was every year divisible by 4. The pope decreed
  1059.                that from then on, a leap year is every year divisible 4
  1060.                except those divisible by 100 but including those divisible
  1061.                by 400). We are still using the Gregorian calendar today.
  1062.  
  1063.      Return    n/a
  1064.  
  1065.      See also  zDate::IsLeapYear(); zDate::DayNumber();
  1066.  
  1067.      Example   n/a
  1068.  
  1069. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1070. October 26, 1996
  1071. San Angelo, TX
  1072. Branislav L. Slantchev
  1073. Silicon Creations, Inc.
  1074.