home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c017 / 34.ddi / DATECLS3.ZIP / DATECLS3.DOC < prev    next >
Encoding:
Text File  |  1991-07-15  |  5.6 KB  |  124 lines

  1. In the beginning Steve Marcus (CIS 72007,1233) posted a basic date
  2. manipulation/arithmetic class produced with Borland C++ 2.0 in the 
  3. BPROGB forum, with a request for suggestions and enhancements. This was
  4. on 6/19/91.
  5.  
  6. A rather enterprising gentleman by the name of Eric Simon (CIS 70540,1522)
  7. accepted the challenge, and produced a new and improved version in the 
  8. course of a project he was developing at work. He contributed the results
  9. to the forum on 6/29/91, also inviting enhancements and comments.
  10.  
  11. Coincidentally, I developed a need for a universal date conversion routine
  12. about the same time for use in a business project I was developing as well.
  13. Browsing the same forum, I encountered Eric's class, which provided much of
  14. the functionality I needed  - the basic julian-gregorian and day of week
  15. conversion algorithms - relieving me of the task of researching or re-
  16. inventing them. He had also added overloaded + and - operators for 
  17. incrementing date objects by integer days, as well as several print functions.
  18.  
  19. I needed additional features for my implementations, so I set about adding
  20. to the class. As is my habit, I got carried away. 
  21.  
  22. The class now has:
  23.  
  24.     1. A full set of constructors, allowing    construction and re-setting
  25.     of any date object from a julian date (the universal kind, relative
  26.     to 1/1/4713 B.C.E., not the YYDDD kind); from a date string (i.e. 
  27.     11/15/1991);from another date object (copy constructor); or from a
  28.     "date" struct as defined in dos.h and returned by getdate(). A date
  29.     object may also be set to the current system date by assigning it to 
  30.     the string "today" (case-insensitive).
  31.  
  32.     2. A full set of comparison operators ( <, <=, >, >=, ==, !=), 
  33.     defined as friend functions so that date objects may be freely
  34.     compared to other date objects, to julian dates, or to strings.
  35.  
  36.     3. A full set of arithmetic operators ( +, -, ++, --, += and -=).
  37.     Additionally, two date objects may now be subtracted to find the
  38.     number of days between them.
  39.  
  40.     4. I have consolidated the print functions into one function,
  41.     formatDate, which accepts an enum value as its format type.
  42.  
  43.     MDY  - returns a buffer with the date formatted as MM/DD/YYYY
  44.     DAY  - returns a buffer with the day of the week name only
  45.     MONTH- returns a buffer with the month name only
  46.     FULL - returns a buffer with the date formatted as DAY MMMMM DD, YYYY
  47.     EUROPEAN- returns a buffer with the date formatted as DD MMMMMM, YYYY
  48.  
  49.     5. The ostream << operator has been overloaded as a friend function
  50.     to handle Date objects. In this implementation the format returned
  51.     is fixed at MM/DD/YYYY, however an equivalent to the ios::setf
  52.     function could be added to maintain a static member in the Date
  53.     class to handle multiple formatting options. A companion << operator
  54.     has been included to handle dos.h date structs, which are returned
  55.     by the getDate() function.
  56.  
  57.     6. Several utility functions have been provided:
  58.  
  59.         isLeapYear - returns 1 if a leap year, 0 if not
  60.         dayOfYear  - returns the day relative to Jan. 1
  61.         eom        - returns a dos.h "date" struct (format YYYYDDMM)
  62.                  with the last day of the month of the date object
  63.         getDate    - returns a dos.h "date" struct (format YYYYDDMM)
  64.                  equivalent to the date object
  65.  
  66.  
  67. IMPLEMENTATION NOTES.
  68.  
  69.     I have attempted to optimize the code for the Borland C++ compiler,
  70.     including the specification of const where applicable, the passing
  71.     of references where advisable, and the use of constructor initializers
  72.     where needed. However I have not made an exhaustive analysis of this
  73.     subject.
  74.  
  75.     Those of you who are using Eric's version will note that I have 
  76.     capatilized the class name to Date, to avoid conflict with Borland's
  77.     "date" struct defined in DOS.H, which is also used by two functions.
  78.     Please be wary of the potential for capitalization errors here.
  79.     Also, I have altered the capitalization    of several function names
  80.     to conform with Borland's suggested convention.
  81.  
  82.     Also, I reorganized the source according to common distribution
  83.     formats.
  84.  
  85.     Thus, this ZIP file contains:
  86.  
  87.         DATECLS3.HPP    -     the header file
  88.         DATECLS3.CPP    -    the member functions
  89.         DATEDEMO.CPP    -    a test program (and a messy one at that)
  90.         DATECLS3.DOC    -    the file you're reading
  91.  
  92.     
  93. Future possibilities for enhancement include:
  94.     
  95.     1. Maintenance of a static variable to handle global date format
  96.        preferences (MDY, FULL, etc.) which would be used to control
  97.        the overloaded << operator (now fixed at the MDY format). This
  98.        would be more convenient than using the formatDate routine.
  99.  
  100.     2. Maintenance of a static variable to handle other print format
  101.        preferences. (Ideas would be to strip the century from the
  102.        MDY format (i.e 10/15/91 instead of 10/15/1991), print 
  103.        abbreviated day or month names (i.e. MON, TUE, JAN, FEB), and
  104.        the like). This would probably be a set of bit flags which would
  105.        work (and be set) like the ios::setf options.
  106.  
  107.     3. Adding a derived Time class, for those applications which require
  108.        the ability to track more than just dates. This would allow the
  109.        manipulation of times for all dates (not just since 1980), and
  110.        arithmetic calculations as well.
  111.  
  112. This is a truly pleasing example of co-operation among professionals, and 
  113. an "object" study in the code reusability of OOP, resulting in three releases
  114. of one class within a single month by three different analysts who have never
  115. met. I thank Steve and Eric for their inspiration and generousity, and hereby
  116. contribute my additions to the public domain.
  117.  
  118. I would welcome further comments, suggestions and enhancements as well.
  119. Good luck!
  120.  
  121.                     Christopher Hill
  122.                     72030,2606
  123.  
  124.