home *** CD-ROM | disk | FTP | other *** search
- In the beginning Steve Marcus (CIS 72007,1233) posted a basic date
- manipulation/arithmetic class produced with Borland C++ 2.0 in the
- BPROGB forum, with a request for suggestions and enhancements. This was
- on 6/19/91.
-
- A rather enterprising gentleman by the name of Eric Simon (CIS 70540,1522)
- accepted the challenge, and produced a new and improved version in the
- course of a project he was developing at work. He contributed the results
- to the forum on 6/29/91, also inviting enhancements and comments.
-
- Coincidentally, I developed a need for a universal date conversion routine
- about the same time for use in a business project I was developing as well.
- Browsing the same forum, I encountered Eric's class, which provided much of
- the functionality I needed - the basic julian-gregorian and day of week
- conversion algorithms - relieving me of the task of researching or re-
- inventing them. He had also added overloaded + and - operators for
- incrementing date objects by integer days, as well as several print functions.
-
- I needed additional features for my implementations, so I set about adding
- to the class. As is my habit, I got carried away.
-
- The class now has:
-
- 1. A full set of constructors, allowing construction and re-setting
- of any date object from a julian date (the universal kind, relative
- to 1/1/4713 B.C.E., not the YYDDD kind); from a date string (i.e.
- 11/15/1991);from another date object (copy constructor); or from a
- "date" struct as defined in dos.h and returned by getdate(). A date
- object may also be set to the current system date by assigning it to
- the string "today" (case-insensitive).
-
- 2. A full set of comparison operators ( <, <=, >, >=, ==, !=),
- defined as friend functions so that date objects may be freely
- compared to other date objects, to julian dates, or to strings.
-
- 3. A full set of arithmetic operators ( +, -, ++, --, += and -=).
- Additionally, two date objects may now be subtracted to find the
- number of days between them.
-
- 4. I have consolidated the print functions into one function,
- formatDate, which accepts an enum value as its format type.
-
- MDY - returns a buffer with the date formatted as MM/DD/YYYY
- DAY - returns a buffer with the day of the week name only
- MONTH- returns a buffer with the month name only
- FULL - returns a buffer with the date formatted as DAY MMMMM DD, YYYY
- EUROPEAN- returns a buffer with the date formatted as DD MMMMMM, YYYY
-
- 5. The ostream << operator has been overloaded as a friend function
- to handle Date objects. In this implementation the format returned
- is fixed at MM/DD/YYYY, however an equivalent to the ios::setf
- function could be added to maintain a static member in the Date
- class to handle multiple formatting options. A companion << operator
- has been included to handle dos.h date structs, which are returned
- by the getDate() function.
-
- 6. Several utility functions have been provided:
-
- isLeapYear - returns 1 if a leap year, 0 if not
- dayOfYear - returns the day relative to Jan. 1
- eom - returns a dos.h "date" struct (format YYYYDDMM)
- with the last day of the month of the date object
- getDate - returns a dos.h "date" struct (format YYYYDDMM)
- equivalent to the date object
-
-
- IMPLEMENTATION NOTES.
-
- I have attempted to optimize the code for the Borland C++ compiler,
- including the specification of const where applicable, the passing
- of references where advisable, and the use of constructor initializers
- where needed. However I have not made an exhaustive analysis of this
- subject.
-
- Those of you who are using Eric's version will note that I have
- capatilized the class name to Date, to avoid conflict with Borland's
- "date" struct defined in DOS.H, which is also used by two functions.
- Please be wary of the potential for capitalization errors here.
- Also, I have altered the capitalization of several function names
- to conform with Borland's suggested convention.
-
- Also, I reorganized the source according to common distribution
- formats.
-
- Thus, this ZIP file contains:
-
- DATECLS3.HPP - the header file
- DATECLS3.CPP - the member functions
- DATEDEMO.CPP - a test program (and a messy one at that)
- DATECLS3.DOC - the file you're reading
-
-
- Future possibilities for enhancement include:
-
- 1. Maintenance of a static variable to handle global date format
- preferences (MDY, FULL, etc.) which would be used to control
- the overloaded << operator (now fixed at the MDY format). This
- would be more convenient than using the formatDate routine.
-
- 2. Maintenance of a static variable to handle other print format
- preferences. (Ideas would be to strip the century from the
- MDY format (i.e 10/15/91 instead of 10/15/1991), print
- abbreviated day or month names (i.e. MON, TUE, JAN, FEB), and
- the like). This would probably be a set of bit flags which would
- work (and be set) like the ios::setf options.
-
- 3. Adding a derived Time class, for those applications which require
- the ability to track more than just dates. This would allow the
- manipulation of times for all dates (not just since 1980), and
- arithmetic calculations as well.
-
- This is a truly pleasing example of co-operation among professionals, and
- an "object" study in the code reusability of OOP, resulting in three releases
- of one class within a single month by three different analysts who have never
- met. I thank Steve and Eric for their inspiration and generousity, and hereby
- contribute my additions to the public domain.
-
- I would welcome further comments, suggestions and enhancements as well.
- Good luck!
-
- Christopher Hill
- 72030,2606
-