home *** CD-ROM | disk | FTP | other *** search
- #ifndef __cplusplus
- #error Requires C++ Compiler
- #endif
-
- #ifndef __TDate_
- #define __TDate_
-
- #if !defined( __STDIO_H )
- #include <stdio.h>
- #endif
-
- #if !defined( __STRING_H )
- #include <string.h>
- #endif
-
- #if !defined( __STDLIB_H )
- #include <stdlib.h>
- #endif
-
- #if !defined( __IOSTREAM_H )
- #include <iostream.h>
- #endif
-
- #if !defined( __DOS_H )
- #include <dos.h>
- #endif
-
- #if !defined( __CTYPE_H )
- #include <ctype.h>
- #endif // __CTYPE_H
-
- #define Uses_TStringCollection
-
- #include <tv.h>
-
- const int ABBR_LENGTH = 3;
-
- const int maxLine = 81;
-
- const enum format_type {MDY, DAY, MONTH, FULL, EUROPEAN};
- const enum {OFF, ON};
-
- const unsigned char NO_CENTURY = 0x02;
- const unsigned char DATE_ABBR = 0x04;
-
- const long PXOffset = 1721424L;
-
-
- class TParser : public TStringCollection
- {
-
- public:
-
- TParser( short aLimit, short aDelta ) :
- TStringCollection( aLimit, aDelta) {}
- #pragma argsused
- virtual int compare(void *key1, void *key2)
- {
- // add in order encountered
- return -1;
- };
- void parse( char *line );
-
- };
-
-
- class TDate
- {
- protected:
- unsigned long julian; // days since 1/1/4713 B.C.
- int year;
- int month;
- int day;
- int day_of_week; // 1 = Sunday, ... 7 = Saturday
-
- private:
- int DisplayFormat;
- unsigned char DisplayOptions;
-
- void julian_to_mdy (void); // convert julian day to mdy
- void julian_to_wday (void); // convert julian day to day_of_week
- void mdy_to_julian (void); // convert mdy to julian day
-
- int char_to_month( const char *charMonth); // convert month name to month value
-
- public:
-
- TDate ();
- TDate (const long aJulDate, const long offset = 0);
- TDate (const int m, const int d, const int y);
- TDate (char *dat);
- TDate (const date &ds);
- TDate (const TDate &dt);
-
- TDate &operator + (const long i);
- TDate &operator - (const long i);
- long operator - (const TDate &dt);
- TDate &operator += (const long i);
- TDate &operator -= (const long i);
- TDate &operator ++ (void); // pre increment function
- TDate &operator ++ (int); // post increment function
- TDate &operator -- (void); // pre decrement function
- TDate &operator -- (int); // post decrement function
-
- friend int operator < (const TDate &dt1, const TDate &dt2);
- friend int operator <= (const TDate &dt1, const TDate &dt2);
- friend int operator > (const TDate &dt1, const TDate &dt2);
- friend int operator >= (const TDate &dt1, const TDate &dt2);
- friend int operator == (const TDate &dt1, const TDate &dt2);
- friend int operator != (const TDate &dt1, const TDate &dt2);
-
- friend ostream &operator << (ostream &os, const TDate &dt);
- friend ostream &operator << (ostream &os, const date &dt);
-
- char *formatDate (const int type=DisplayFormat) const;
- void setFormat (const int format);
- int setOption (const int option, const int action=ON);
- int setDate (const char *charDate); // returns 1 if successful, 0 if not
- int setDate (const long aJulDate, const long offset = 0 ); // returns 1 if successful, 0 if not
- void incrMonth(void); // increments the month
- void decrMonth(void); // decrements the month
- void incrYear(void); // increments the year
- void decrYear(void); // decrements the year
-
- long julDate(void) const; // returns julian date
- long PXDate(void) const; // returns date in PX format
- int dayOfYear(void) const; // returns relative date since Jan. 1
- int isLeapYear(void) const; // returns 1 if leap year, 0 if not
-
- // note that the next functions return a date struct as defined in
- // dos.h (distinct from the TDate class) Order is year, day, month.
- date eom(void) const; // returns last day of month in object
- date getDate(void) const; // returns a date structure
- } ;
-
- #endif
-