home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / tfield / tdate.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-03  |  3.7 KB  |  137 lines

  1. #ifndef __cplusplus
  2. #error  Requires C++ Compiler
  3. #endif
  4.  
  5. #ifndef __TDate_
  6. #define __TDate_
  7.  
  8. #if !defined( __STDIO_H )
  9. #include <stdio.h>
  10. #endif
  11.  
  12. #if !defined( __STRING_H )
  13. #include <string.h>
  14. #endif
  15.  
  16. #if !defined( __STDLIB_H )
  17. #include <stdlib.h>
  18. #endif
  19.  
  20. #if !defined( __IOSTREAM_H )
  21. #include <iostream.h>
  22. #endif
  23.  
  24. #if !defined( __DOS_H )
  25. #include <dos.h>
  26. #endif
  27.  
  28. #if !defined( __CTYPE_H )
  29. #include <ctype.h>
  30. #endif  // __CTYPE_H
  31.  
  32. #define Uses_TStringCollection
  33.  
  34. #include <tv.h>
  35.  
  36. const int ABBR_LENGTH = 3;
  37.  
  38. const int maxLine = 81;
  39.  
  40. const enum format_type {MDY, DAY, MONTH, FULL, EUROPEAN};
  41. const enum {OFF, ON};
  42.  
  43. const unsigned char NO_CENTURY  = 0x02;
  44. const unsigned char DATE_ABBR   = 0x04;
  45.  
  46. const long PXOffset = 1721424L;
  47.  
  48.  
  49. class TParser : public TStringCollection
  50. {
  51.  
  52. public:
  53.  
  54.     TParser( short aLimit, short aDelta ) :
  55.         TStringCollection( aLimit, aDelta) {}
  56.     #pragma argsused
  57.     virtual int compare(void *key1, void *key2)
  58.     {
  59.         // add in order encountered
  60.         return -1;
  61.     };
  62.     void parse( char *line );
  63.  
  64. };
  65.  
  66.  
  67. class TDate
  68. {
  69.     protected:
  70.         unsigned long julian;          // days since 1/1/4713 B.C.
  71.         int year;
  72.         int month;
  73.         int day;
  74.         int day_of_week;                 // 1 = Sunday, ... 7 = Saturday
  75.  
  76.     private:
  77.         int DisplayFormat;
  78.         unsigned char DisplayOptions;
  79.  
  80.         void julian_to_mdy (void);         // convert julian day to mdy
  81.         void julian_to_wday (void);        // convert julian day to day_of_week
  82.         void mdy_to_julian (void);         // convert mdy to julian day
  83.  
  84.         int char_to_month( const char *charMonth);    // convert month name to month value
  85.  
  86.     public:
  87.  
  88.         TDate ();
  89.         TDate (const long aJulDate, const long offset = 0);
  90.         TDate (const int m, const int d, const int y);
  91.         TDate (char *dat);
  92.         TDate (const date &ds);
  93.         TDate (const TDate &dt);
  94.  
  95.         TDate &operator +  (const long i);
  96.         TDate &operator -  (const long i);
  97.         long  operator -  (const TDate &dt);
  98.         TDate &operator += (const long i);
  99.         TDate &operator -= (const long i);
  100.         TDate &operator ++ (void); // pre increment function
  101.         TDate &operator ++ (int); // post increment function
  102.         TDate &operator -- (void); // pre decrement function
  103.         TDate &operator -- (int); // post decrement function
  104.  
  105.         friend int operator <  (const TDate &dt1, const TDate &dt2);
  106.         friend int operator <= (const TDate &dt1, const TDate &dt2);
  107.         friend int operator >  (const TDate &dt1, const TDate &dt2);
  108.         friend int operator >= (const TDate &dt1, const TDate &dt2);
  109.         friend int operator == (const TDate &dt1, const TDate &dt2);
  110.         friend int operator != (const TDate &dt1, const TDate &dt2);
  111.  
  112.         friend ostream &operator << (ostream &os, const TDate &dt);
  113.         friend ostream &operator << (ostream &os, const date &dt);
  114.  
  115.         char *formatDate (const int type=DisplayFormat) const;
  116.         void setFormat (const int format);
  117.         int setOption (const int option, const int action=ON);
  118.         int setDate (const char *charDate); // returns 1 if successful, 0 if not
  119.         int setDate (const long aJulDate, const long offset = 0 ); // returns 1 if successful, 0 if not
  120.         void incrMonth(void); // increments the month
  121.         void decrMonth(void); // decrements the month
  122.         void incrYear(void); // increments the year
  123.         void decrYear(void); // decrements the year
  124.  
  125.         long julDate(void) const;  // returns julian date
  126.         long PXDate(void) const; // returns date in PX format
  127.         int dayOfYear(void) const;  // returns relative date since Jan. 1
  128.         int isLeapYear(void) const;  // returns 1 if leap year, 0 if not
  129.  
  130.         // note that the next functions return a date struct as defined in
  131.         // dos.h (distinct from the TDate class) Order is year, day, month.
  132.         date eom(void) const;  // returns last day of month in object
  133.         date getDate(void) const;  // returns a date structure
  134. } ;
  135.  
  136. #endif
  137.