home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dtime / data.1 / Datetime.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-08  |  23.2 KB  |  680 lines

  1. /*
  2. Module : DATETIME.H
  3. Purpose: Defines the interface to a number of Date and Date/Time classes
  4. Created: PJN / DATE/1 / 05-05-1995
  5. History: None
  6.  
  7. Copyright (c) 1995 by PJ Naughter.  
  8. All rights reserved.
  9.  
  10. */
  11.  
  12. #ifndef __DATE_H__
  13.  
  14.  
  15. ////////////////////////////////// Macros /////////////////////////////////////
  16.  
  17. #define __DATE_H__
  18.  
  19.                       
  20.  
  21. ////////////////////////////////// Includes ///////////////////////////////////
  22.  
  23. #include <afx.h>
  24. #include <iostream.h>
  25. #include "win32sup.h"
  26.  
  27.  
  28.  
  29. ////////////////////////////// Date Enums & Structs ///////////////////////////
  30.  
  31. enum CalendarType { JULIAN, GREGORIAN };
  32.  
  33.  
  34. struct DateS
  35. {
  36.   LONG lYear;
  37.   WORD wMonth;
  38.   WORD wDay;
  39.   WORD wWday;
  40.   WORD wYday;
  41.   CalendarType ct;
  42. };
  43.  
  44.  
  45. enum TimeFrame {UTC=0,
  46.                 ET, 
  47.                 LOCAL};
  48.  
  49.  
  50. struct DateLS
  51. {
  52.   LONG lYear;
  53.   WORD wMonth;
  54.   WORD wDay;
  55.   WORD wWday;
  56.   WORD wYday;
  57.   WORD wHour;
  58.   WORD wMinute;
  59.   WORD wSecond;
  60.   WORD wMilliSeconds;
  61.   CalendarType ct;
  62.   TimeFrame tf;
  63. };
  64.  
  65.  
  66. /////////////////////////////// Free sub-programs (aka functions) /////////////
  67.                                             
  68.  
  69.      
  70.  
  71. /////////////////////////////// Classes ///////////////////////////////////////
  72.  
  73. // forward declarations
  74. class CLDate;
  75. class CLTimeOfDay;
  76.    
  77.    
  78.    
  79.    
  80. // A Date class with a granularity of 1 Day
  81.  
  82. class AFX_EXT_CLASS CDate : public CObject
  83. {
  84.   DECLARE_SERIAL(CDate)
  85.  
  86. public:
  87.   friend class CLDate;
  88.  
  89.   enum MONTH { JANUARY=1,
  90.                FEBRUARY=2,
  91.                MARCH=3,
  92.                APRIL=4,
  93.                MAY=5,
  94.                JUNE=6,
  95.                JULY=7,
  96.                AUGUST=8,
  97.                SEPTEMBER=9,
  98.                OCTOBER=10,
  99.                NOVEMBER=11,
  100.                DECEMBER=12};
  101.  
  102.   enum DayOfWeek { SUNDAY=1,
  103.                    MONDAY=2,
  104.                    TUESDAY=3,
  105.                    WEDNESDAY=4,
  106.                    THURSDAY=5,
  107.                    FRIDAY=6,
  108.                    SATURDAY=7};
  109.  
  110.   enum DateEpoch { EPOCH_JD,
  111.                    EPOCH_MJD,
  112.                    EPOCH_1900,
  113.                    EPOCH_1950,
  114.                    EPOCH_CTIME,
  115.                    EPOCH_2000,
  116.                    EPOCH_GREG};
  117.  
  118.   
  119.  
  120.   //constructors
  121.   EXPORT16 CDate();
  122.   EXPORT16 CDate(LONG Year, WORD Month, WORD Day);
  123.   EXPORT16 CDate(const SYSTEMTIME& st);
  124.   EXPORT16 CDate(LONG Year, WORD Month, WORD WeekOfMonth, WORD DayOfWeek); 
  125.   EXPORT16 CDate(LONG Days, DateEpoch e);
  126.   EXPORT16 CDate(const CDate& d);
  127.   EXPORT16 CDate(const CTime& ctime);
  128. #ifdef _WIN32
  129.   EXPORT16 CDate(const COleDateTime& oleTime);
  130. #endif  
  131.  
  132.  
  133.   //Set operators
  134.   CDate& EXPORT16 Set();
  135.   CDate& EXPORT16 Set(LONG Year, WORD Month, WORD Day);
  136.   CDate& EXPORT16 Set(DateS ds);
  137.   CDate& EXPORT16 Set(const SYSTEMTIME& st);
  138.   CDate& EXPORT16 Set(LONG Year, WORD Month, WORD WeekOfMonth, WORD DayOfWeek); 
  139.   CDate& EXPORT16 Set(LONG Days, DateEpoch e);
  140.   CDate& EXPORT16 Set(const CTime& ctime);
  141. #ifdef _WIN32
  142.   CDate& EXPORT16 Set(const COleDateTime& oleTime);
  143. #endif  
  144.  
  145.  
  146.   //statics constructors
  147.   static CDate EXPORT16 CurrentDate();
  148.   static CDate EXPORT16 FirstCurrentMonth(); 
  149.   static CDate EXPORT16 LastCurrentMonth();  
  150.   static CDate EXPORT16 FirstCurrentYear();
  151.   static CDate EXPORT16 LastCurrentYear();
  152.   static CDate EXPORT16 JDEpoch(); 
  153.   static CDate EXPORT16 MJDEpoch();
  154.   static CDate EXPORT16 Epoch1900();
  155.   static CDate EXPORT16 Epoch1950();
  156.   static CDate EXPORT16 EpochCTime();
  157.   static CDate EXPORT16 Epoch2000();
  158.   static CDate EXPORT16 GregorianEpoch();
  159.   static void ClearStatics(); //Deallocate memory used by statics
  160.   
  161.  
  162.   //static operations
  163.   static BOOL EXPORT16     IsLeap(LONG Year);
  164.   static WORD EXPORT16     DaysInYear(LONG Year);
  165.   static WORD EXPORT16     DaysInMonth(WORD Month, BOOL IsLeap);
  166.   static WORD EXPORT16     DaysSinceJan1(WORD Month, WORD Day, BOOL IsLeap);
  167.   static WORD EXPORT16     DaysSinceJan0(WORD Month, WORD Day, BOOL IsLeap);
  168.   static void EXPORT16     SetDefaultFormat(const CString& Format);
  169.   static CString& EXPORT16 GetDefaultFormat();
  170.   static WORD EXPORT16     CurrentMonth();
  171.   static WORD EXPORT16     CurrentDay();
  172.   static LONG EXPORT16     CurrentYear();
  173.   static WORD EXPORT16     CurrentDayOfWeek();
  174.   static void EXPORT16     SetBeginingDayOfWeek(WORD BeginOfWeek);
  175.   static WORD EXPORT16     GetBeginingDayOfWeek();
  176.   static void EXPORT16     SetEndJulianCalendar(LONG Year, WORD Month, WORD Day);
  177.   static void EXPORT16     SetBeginGregCalendar(LONG Year, WORD Month, WORD Day);
  178.   static DateS EXPORT16    GetEndJulianCalendar();
  179.   static DateS EXPORT16    GetBeginGregCalendar();
  180.   static BOOL EXPORT16     InGregorianCalendar(LONG Year, WORD Month, WORD Day);
  181. #ifdef _DEBUG
  182.   static BOOL EXPORT16     SetDoConstructorAsserts(BOOL bDoAsserts);
  183. #endif
  184.   static CString& EXPORT16 GetFullStringDayOfWeek(WORD DayOfWeek);
  185.   static CString& EXPORT16 GetAbrStringDayOfWeek(WORD DayOfWeek);
  186.   static CString& EXPORT16 GetFullStringMonth(WORD Month);
  187.   static CString& EXPORT16 GetAbrStringMonth(WORD Month);
  188.  
  189.   
  190.   //static Holiday constructors
  191.   static CDate EXPORT16 NewYearsDay(LONG Year=CDate::CurrentYear());
  192.   static CDate EXPORT16 ValentinesDay(LONG Year=CDate::CurrentYear());
  193.   static CDate EXPORT16 AshWednesday(LONG Year=CDate::CurrentYear());
  194.   static CDate EXPORT16 StPatricksDay(LONG Year=CDate::CurrentYear());
  195.   static CDate EXPORT16 GoodFriday(LONG Year=CDate::CurrentYear());
  196.   static CDate EXPORT16 EasterSunday(LONG Year=CDate::CurrentYear());
  197.   static CDate EXPORT16 CanadaDay(LONG Year=CDate::CurrentYear());
  198.   static CDate EXPORT16 IndependenceDay(LONG Year=CDate::CurrentYear());
  199.   static CDate EXPORT16 BastilleDay(LONG Year=CDate::CurrentYear());
  200.   static CDate EXPORT16 ChristmasDay(LONG Year=CDate::CurrentYear());
  201.  
  202.   
  203.   //Operations
  204.   WORD EXPORT16       DaysSinceJan1() const;
  205.   WORD EXPORT16       DaysSinceJan0() const;
  206.   DateS EXPORT16      GetDate() const;
  207.   WORD EXPORT16       GetDay() const;
  208.   WORD EXPORT16       GetMonth() const;
  209.   LONG EXPORT16       GetYear() const;
  210.   LONG EXPORT16       GetCEBCEYear(BOOL& IsCE) const;
  211.   WORD EXPORT16       Get2DigitYear() const;
  212.   LONG EXPORT16       Since1900Epoch() const;
  213.   LONG EXPORT16       Since1950Epoch() const;
  214.   LONG EXPORT16       SinceCTimeEpoch() const;
  215.   LONG EXPORT16       Since2000Epoch() const;
  216.   LONG EXPORT16       GDN() const;
  217.   LONG EXPORT16       JD() const;
  218.   BOOL EXPORT16       IsLeap() const;
  219.   WORD EXPORT16       DaysInYear() const;
  220.   WORD EXPORT16       DaysInMonth() const;
  221.   void EXPORT16       AddYear(int Years=1);
  222.   void EXPORT16       AddWeek(int Weeks=1);
  223.   void EXPORT16       AddMonth(int Months=1);
  224.   WORD EXPORT16       GetDayOfWeek() const; 
  225.   CString& EXPORT16   GetStringCEBCEYear() const;    
  226.   CString& EXPORT16   GetFullStringDayOfWeek() const;
  227.   CString& EXPORT16   GetAbrStringDayOfWeek() const;
  228.   CString& EXPORT16   GetFullStringMonth() const;
  229.   CString& EXPORT16   GetAbrStringMonth() const;
  230.   SYSTEMTIME EXPORT16 GetSYSTEMTIME() const;
  231.   tm   EXPORT16       GetTM() const;
  232.   WORD EXPORT16       GetWeekOfYear() const;    
  233.   WORD EXPORT16       GetWeekOfMonth() const;
  234.   BOOL EXPORT16       IsValid() const;          
  235.   LONG EXPORT16       Collate() const;          
  236.   BOOL EXPORT16       InGregorianCalendar() const;
  237.                                           
  238.                                         
  239.   //Creation of other CDate's from this instance
  240.   CDate EXPORT16 FirstThisMonth() const;
  241.   CDate EXPORT16 LastThisMonth() const;
  242.   CDate EXPORT16 FirstThisYear() const;
  243.   CDate EXPORT16 LastThisYear() const;
  244.   
  245.  
  246.   //Overloaded Arithmetic Operators
  247.   CDate& EXPORT16 operator=(const CDate& d);
  248.   CDate  EXPORT16 operator+(LONG Days) const;
  249.   LONG   EXPORT16 operator-(const CDate& d) const;
  250.   CDate  EXPORT16 operator-(LONG Days) const;
  251.   CDate& EXPORT16 operator+=(LONG Days);
  252.   CDate& EXPORT16 operator-=(LONG Days);
  253.   CDate& EXPORT16 operator++();
  254.   CDate& EXPORT16 operator--();
  255.  
  256.  
  257.   //Overloaded Equality operators
  258.   BOOL EXPORT16 operator==(const CDate& d) const;
  259.   BOOL EXPORT16 operator>(const CDate& d) const;
  260.   BOOL EXPORT16 operator>=(const CDate& d) const;
  261.   BOOL EXPORT16 operator<(const CDate& d) const;
  262.   BOOL EXPORT16 operator<=(const CDate& d) const;
  263.   BOOL EXPORT16 operator!=(const CDate& d) const;
  264.  
  265.  
  266.   //Diagnostics / Debug
  267.   #ifdef _DEBUG
  268.   virtual void EXPORT16 AssertValid() const;
  269.   virtual void EXPORT16 Dump(CDumpContext& dc) const;
  270.   #endif
  271.  
  272.  
  273.   //Display
  274.   CString& EXPORT16 Format(const CString& sFormat=CDate::GetDefaultFormat()) const;
  275.   
  276.  
  277.   //Serialization
  278.   virtual void EXPORT16 Serialize(CArchive& ar);
  279.  
  280.  
  281.   //streaming
  282.   friend ostream&  AFX_EXT_API EXPORT16 operator<<(ostream& os, const CDate& Date);
  283.   friend CArchive& AFX_EXT_API EXPORT16 operator<<(CArchive& ar, CDate& Date);
  284.   friend CArchive& AFX_EXT_API EXPORT16 operator>>(CArchive& ar, CDate& Date);
  285.   
  286.  
  287. protected:
  288.   LONG m_lDays;                      //Count of days since 15 October 1582 (Gregorian Calendrical System or n.s) 
  289.   BOOL m_bInGregCalendar;            //Is this date in the Gregorian Calendar
  290.     
  291.   static CString sm_sBuffer;         //local Buffer for string return values
  292.   static CString sm_sDefaultFormat;  //Default Format string
  293.   static WORD    sm_wBeginOfWeek;    //Day of Week considered the begining of the week
  294.  
  295.   static LONG sm_lEndJulianYear;     //The Date when the Julian Calendar Finished
  296.   static WORD sm_wEndJulianMonth;
  297.   static WORD sm_wEndJulianDay;
  298.  
  299.   static LONG sm_lBeginGregYear;     //The Date when the Gregorian Calendar Started
  300.   static WORD sm_wBeginGregMonth;
  301.   static WORD sm_wBeginGregDay;
  302.   static BOOL sm_bDoAsserts;         //Do constructor asserts
  303. };
  304.  
  305.  
  306.  
  307.  
  308. // A Time span class with a granularity of 1 millisecond which
  309. // is used in conjunction with the time class CLDate
  310.  
  311. class AFX_EXT_CLASS CLTimeSpan : public CObject
  312. {
  313. public:
  314.   friend class CLDate;
  315.   friend class CLTimeOfDay;
  316.  
  317.   DECLARE_SERIAL(CLTimeSpan)
  318.     
  319.   //constructors
  320.   EXPORT16 CLTimeSpan();
  321.   EXPORT16 CLTimeSpan(LONG Day, WORD Hour, WORD Minute, 
  322.              WORD Second, WORD MilliSecond);
  323.   EXPORT16 CLTimeSpan(const CLTimeSpan& lts);
  324.   EXPORT16 CLTimeSpan(const CTimeSpan& ts);
  325.   EXPORT16 CLTimeSpan(const CLTimeOfDay& tod);
  326. #ifdef _WIN32
  327.   EXPORT16 CLTimeSpan(const COleDateTimeSpan& oleTimeSpan);
  328. #endif  
  329.   EXPORT16 CLTimeSpan(const double& Seconds);
  330.  
  331.   //Set operators
  332.   CLTimeSpan& EXPORT16 Set();
  333.   CLTimeSpan& EXPORT16 Set(LONG Day, WORD Hour, WORD Minute, 
  334.                   WORD Second, WORD MilliSecond);
  335.   CLTimeSpan& EXPORT16 Set(const CTimeSpan& ts);
  336.   CLTimeSpan& EXPORT16 Set(const CLTimeOfDay& tod);
  337. #ifdef _WIN32
  338.   CLTimeSpan& EXPORT16 Set(const COleDateTimeSpan& oleTimeSpan);
  339. #endif  
  340.   CLTimeSpan& EXPORT16 Set(const double& Seconds);
  341.   
  342.   //statics constructors
  343.   static CLTimeSpan EXPORT16 OneCivilYear();
  344.   static CLTimeSpan EXPORT16 OneDay();
  345.   static CLTimeSpan EXPORT16 OneHour();
  346.   static CLTimeSpan EXPORT16 OneMinute();
  347.   static CLTimeSpan EXPORT16 OneSecond();
  348.   static CLTimeSpan EXPORT16 OneMilliSecond();  
  349.  
  350.   
  351.   //static operations
  352.   static void     EXPORT16 SetDefaultFormat(const CString& Format);
  353.   static CString& EXPORT16 GetDefaultFormat();
  354. #ifdef _DEBUG
  355.   static BOOL     EXPORT16 SetDoConstructorAsserts(BOOL bDoAsserts);
  356. #endif                                                            
  357.   static void ClearStatics(); //Deallocate memory used by statics
  358.   
  359.   
  360.   //Operations
  361.   LONG        EXPORT16 GetTotalDays() const; 
  362.   WORD        EXPORT16 GetHours() const; 
  363.   WORD        EXPORT16 GetMinutes() const; 
  364.   WORD        EXPORT16 GetSeconds() const; 
  365.   WORD        EXPORT16 GetMilliSeconds() const; 
  366.   BOOL        EXPORT16 IsValid() const; 
  367.   CLTimeSpan& EXPORT16 Negate();
  368.   BOOL        EXPORT16 IsPositiveSpan() const;
  369.   double      EXPORT16 SecondsAsDouble() const;
  370.                                            
  371.                                         
  372.   //Overloaded Arithmetic Operators
  373.   CLTimeSpan& EXPORT16       operator=(const CLTimeSpan& TimeSpan);
  374.   CLTimeSpan  EXPORT16       operator+(const CLTimeSpan& TimeSpan) const;
  375.   CLTimeSpan  EXPORT16       operator-(const CLTimeSpan& TimeSpan) const;
  376.   CLTimeSpan& EXPORT16       operator+=(CLTimeSpan& TimeSpan);
  377.   CLTimeSpan& EXPORT16       operator-=(CLTimeSpan& TimeSpan);
  378.   friend CLTimeSpan AFX_EXT_API EXPORT16 operator-(const CLTimeSpan& TimeSpan);
  379.   CLTimeSpan  EXPORT16       operator*(WORD Multiplier) const;
  380.   friend CLTimeSpan AFX_EXT_API EXPORT16 operator*(WORD Multiplier, const CLTimeSpan& TimeSpan);
  381.   CLTimeSpan  EXPORT16       operator/(WORD divisor) const;
  382.   CLTimeSpan& EXPORT16       operator*=(WORD Multiplier);
  383.   CLTimeSpan& EXPORT16       operator/=(WORD Divisor);
  384.   
  385.  
  386.  
  387.   //Overloaded Equality operators
  388.   BOOL EXPORT16 operator==(const CLTimeSpan& TimeSpan) const;
  389.   BOOL EXPORT16 operator>(const CLTimeSpan& TimeSpan) const;
  390.   BOOL EXPORT16 operator>=(const CLTimeSpan& TimeSpan) const;
  391.   BOOL EXPORT16 operator<(const CLTimeSpan& TimeSpan) const;
  392.   BOOL EXPORT16 operator<=(const CLTimeSpan& TimeSpan) const;
  393.   BOOL EXPORT16 operator!=(const CLTimeSpan& TimeSpan) const;
  394.  
  395.  
  396.   //Diagnostics / Debug
  397.   #ifdef _DEBUG
  398.   virtual void EXPORT16 AssertValid() const;
  399.   virtual void EXPORT16 Dump(CDumpContext& dc) const;
  400.   #endif
  401.  
  402.  
  403.   //Display
  404.   CString& EXPORT16 Format(const CString& sFormat=CLTimeSpan::GetDefaultFormat()) const;
  405.   
  406.  
  407.   //Serialization
  408.   virtual void EXPORT16 Serialize(CArchive& ar);
  409.  
  410.  
  411.   //streaming
  412.   friend ostream&  AFX_EXT_API EXPORT16 operator<<(ostream& os, const CLTimeSpan& TimeSpan);
  413.   friend CArchive& AFX_EXT_API EXPORT16 operator<<(CArchive& ar, CLTimeSpan& TimeSpan);
  414.   friend CArchive& AFX_EXT_API EXPORT16 operator>>(CArchive& ar, CLTimeSpan& TimeSpan);
  415.   
  416.          
  417. protected:
  418.   double m_dSeconds;
  419.  
  420.   static CString sm_sBuffer;         //local Buffer for string return values
  421.   static CString sm_sDefaultFormat;  //Default Format string
  422.   static BOOL    sm_bDoAsserts;      //Asserts in constructors / castings, otherwise sets date to invalid date
  423. };
  424.  
  425.  
  426.  
  427.  
  428. // A Time of Day class with a granularity of 1 millisecond which
  429. // is used in conjunction with the time class CDate in the CLDate class
  430.  
  431. class AFX_EXT_CLASS CLTimeOfDay : public CObject
  432. {
  433. public:
  434.   friend class CLDate;
  435.   
  436.   DECLARE_SERIAL(CLTimeOfDay)
  437.  
  438.  
  439.   //constructors
  440.   EXPORT16 CLTimeOfDay();
  441.   EXPORT16 CLTimeOfDay(WORD Hour, WORD Minute, 
  442.              WORD Second, WORD MilliSecond);
  443.   EXPORT16 CLTimeOfDay(const SYSTEMTIME& st);             
  444.   EXPORT16 CLTimeOfDay(const CLTimeOfDay& ltod);
  445.   EXPORT16 CLTimeOfDay(DWORD TotalSeconds, WORD MilliSecond);
  446.   EXPORT16 CLTimeOfDay(const double& Seconds);
  447.  
  448.   //Set operators
  449.   CLTimeOfDay& EXPORT16 Set();
  450.   CLTimeOfDay& EXPORT16 Set(WORD Hour, WORD Minute, 
  451.                   WORD Second, WORD MilliSecond);
  452.   CLTimeOfDay& EXPORT16 Set(const SYSTEMTIME& st);          
  453.   CLTimeOfDay& EXPORT16 Set(DWORD TotalSeconds, WORD MilliSecond);   
  454.   CLTimeOfDay& EXPORT16 Set(const double& Seconds);
  455.  
  456.  
  457.   //statics constructors              
  458.   static CLTimeOfDay EXPORT16 CurrentTimeOfDay(TimeFrame tf);
  459.   static CLTimeOfDay EXPORT16 Midnight();
  460.   static CLTimeOfDay EXPORT16 Midday();
  461.  
  462.   
  463.   //static operations
  464.   static void     EXPORT16 SetDefaultFormat(const CString& Format);
  465.   static CString& EXPORT16 GetDefaultFormat();
  466. #ifdef _DEBUG
  467.   static BOOL     EXPORT16 SetDoConstructorAsserts(BOOL bDoAsserts);
  468. #endif
  469.   static void ClearStatics(); //Deallocate memory used by statics  
  470.   
  471.   //Operations
  472.   WORD           EXPORT16 GetHour() const; 
  473.   WORD           EXPORT16 GetMinute() const; 
  474.   WORD           EXPORT16 GetSecond() const; 
  475.   DWORD          EXPORT16 GetTotalSeconds() const;
  476.   WORD           EXPORT16 GetMilliSecond() const; 
  477.   WORD           EXPORT16 GetAMPMHour() const; 
  478.   CString&       EXPORT16 GetAMPMString() const;
  479.   BOOL           EXPORT16 IsValid() const;          
  480.   ULARGE_INTEGER EXPORT16 Collate() const;
  481.   SYSTEMTIME     EXPORT16 GetSYSTEMTIME() const;
  482.   tm             EXPORT16 GetTM() const;
  483.   double         EXPORT16 SecondsAsDouble() const;
  484.   
  485.                                        
  486.                                         
  487.   //Overloaded Arithmetic Operators
  488.   CLTimeOfDay& EXPORT16 operator=(const CLTimeOfDay& Tod);
  489.   CLTimeOfDay  EXPORT16 operator+(const CLTimeSpan& TimeSpan) const;
  490.   CLTimeOfDay  EXPORT16 operator-(const CLTimeSpan& TimeSpan) const;
  491.   CLTimeOfDay& EXPORT16 operator+=(CLTimeSpan& TimeSpan);
  492.   CLTimeOfDay& EXPORT16 operator-=(CLTimeSpan& TimeSpan);
  493.  
  494.  
  495.   //Overloaded Equality operators
  496.   BOOL EXPORT16 operator==(const CLTimeOfDay& Tod) const;
  497.   BOOL EXPORT16 operator>(const CLTimeOfDay& Tod) const;
  498.   BOOL EXPORT16 operator>=(const CLTimeOfDay& Tod) const;
  499.   BOOL EXPORT16 operator<(const CLTimeOfDay& Tod) const;
  500.   BOOL EXPORT16 operator<=(const CLTimeOfDay& Tod) const;
  501.   BOOL EXPORT16 operator!=(const CLTimeOfDay& Tod) const;
  502.  
  503.  
  504.   //Diagnostics / Debug
  505.   #ifdef _DEBUG
  506.   virtual void EXPORT16 AssertValid() const;
  507.   virtual void EXPORT16 Dump(CDumpContext& dc) const;
  508.   #endif
  509.  
  510.  
  511.   //Display
  512.   CString& EXPORT16 Format(const CString& sFormat=CLTimeOfDay::GetDefaultFormat()) const;
  513.   
  514.  
  515.   //Serialization
  516.   virtual void EXPORT16 Serialize(CArchive& ar);
  517.  
  518.  
  519.   //streaming
  520.   friend ostream&  AFX_EXT_API EXPORT16 operator<<(ostream& os, const CLTimeOfDay& Tod);
  521.   friend CArchive& AFX_EXT_API EXPORT16 operator<<(CArchive& ar, CLTimeOfDay& Tod);
  522.   friend CArchive& AFX_EXT_API EXPORT16 operator>>(CArchive& ar, CLTimeOfDay& Tod);
  523.   
  524.          
  525. protected:
  526.   DWORD m_dwTotalSeconds;            //Actual instance data 
  527.   WORD m_wMilliSeconds;
  528.  
  529.   static CString sm_sBuffer;         //local Buffer for string return values
  530.   static CString sm_sDefaultFormat;  //Default Format string
  531.   static BOOL    sm_bDoAsserts;      //Asserts in constructors / castings, otherwise sets date to invalid date
  532. };
  533.  
  534.  
  535.  
  536.  
  537. // A Date class with a granularity of 1 millisecond
  538.  
  539. class AFX_EXT_CLASS CLDate : public CObject
  540. {
  541. public:
  542.   DECLARE_SERIAL(CLDate)
  543.    
  544.   //constructors
  545.   EXPORT16 CLDate();
  546.   EXPORT16 CLDate(LONG Year, WORD Month, WORD Day, 
  547.          WORD Hour, WORD Minute, WORD Second,
  548.          WORD MilliSecond, TimeFrame tf);
  549.   EXPORT16 CLDate(const SYSTEMTIME& st, TimeFrame tf, BOOL bUseDayOfWeek=FALSE);
  550.   EXPORT16 CLDate(LONG Year, WORD Month, WORD WeekOfMonth,
  551.          WORD DayOfWeek, WORD Hour, WORD Minute, WORD Second,
  552.          WORD MilliSecond, TimeFrame tf); 
  553.   EXPORT16 CLDate(LONG Days, CDate::DateEpoch e, WORD Hour, WORD Minute,
  554.          WORD Second, WORD MilliSecond, TimeFrame tf);
  555.   EXPORT16 CLDate(const CLDate& ld);
  556.   EXPORT16 CLDate(const CTime& ct);
  557.   EXPORT16 CLDate(const CDate& Date, const CLTimeOfDay& Tod, TimeFrame tf);
  558. #ifdef _WIN32
  559.   EXPORT16 CLDate(const COleDateTime& oleTime, TimeFrame tf);
  560. #endif  
  561.  
  562.  
  563.   //Set operators
  564.   CLDate& EXPORT16 Set();
  565.   CLDate& EXPORT16 Set(LONG Year, WORD Month, WORD Day,
  566.               WORD Hour, WORD Minute, WORD Second,
  567.               WORD MilliSecond, TimeFrame tf);
  568.   CLDate& EXPORT16 Set(const SYSTEMTIME& st, TimeFrame tf, BOOL bUseDayOfWeek=FALSE);           
  569.   CLDate& EXPORT16 Set(LONG Year, WORD Month, WORD WeekOfMonth, 
  570.               WORD DayOfWeek, WORD Hour, WORD Minute, WORD Second,
  571.               WORD MilliSecond, TimeFrame tf); 
  572.   CLDate& EXPORT16 Set(LONG Days, CDate::DateEpoch e, WORD Hour, WORD Minute,
  573.               WORD Second, WORD MilliSecond, TimeFrame tf);
  574.   CLDate& EXPORT16 Set(const CTime& ct);         
  575.   CLDate& EXPORT16 Set(const CDate& Date, const CLTimeOfDay& Tod, TimeFrame tf);
  576. #ifdef _WIN32
  577.   CLDate& EXPORT16 Set(const COleDateTime& oleTime, TimeFrame tf);
  578. #endif  
  579.  
  580.  
  581.   //static constructors
  582.   static CLDate EXPORT16 CurrentTime(TimeFrame tf);
  583.  
  584.   
  585.   //static operations
  586.   static void       EXPORT16 SetDefaultFormat(const CString& Format);
  587.   static CString&   EXPORT16 GetDefaultFormat();
  588.   static CLTimeSpan EXPORT16 DeltaT(CLDate& ld);
  589.   static BOOL       EXPORT16 CurrentlyInDST();
  590.   static CLTimeSpan EXPORT16 DaylightBias();
  591.   static CLTimeSpan EXPORT16 TimezoneBias();
  592.   static CString&   EXPORT16 DaylightName();
  593.   static CString&   EXPORT16 StandardName();
  594. #ifdef _DEBUG
  595.   static BOOL EXPORT16 SetDoConstructorAsserts(BOOL bDoAsserts);
  596. #endif
  597.   static void ClearStatics(); //Deallocate memory used by statics
  598.   
  599.  
  600.   //Operations
  601.   CDate              EXPORT16 GetCDate() const;
  602.   CLTimeOfDay        EXPORT16 GetCLTimeOfDay() const;
  603.   DateLS             EXPORT16 GetDate() const;
  604.   SYSTEMTIME         EXPORT16 GetSYSTEMTIME() const;
  605.   tm                 EXPORT16 GetTM();  
  606.   void               EXPORT16 AddYear(int Years=1);
  607.   void               EXPORT16 AddWeek(int Weeks=1);
  608.   void               EXPORT16 AddMonth(int Months=1);
  609.   BOOL               EXPORT16 IsValid() const;
  610.   CLTimeSpan         EXPORT16 DeltaT();
  611.   TimeFrame          EXPORT16 SetTimeFrame(TimeFrame tf);
  612.   TimeFrame          EXPORT16 GetTimeFrame() const;
  613.   BOOL               EXPORT16 IsDST();
  614.   CString&           EXPORT16 GetStringTimeFrame() const;
  615.   double             EXPORT16 GSNAsDouble() const;
  616.   double             EXPORT16 GDNAsDouble() const;
  617.                                      
  618.                                         
  619.   //Overloaded Arithmetic Operators
  620.   CLDate&    EXPORT16 operator=(const CLDate& ld);
  621.   CLDate     EXPORT16 operator+(const CLTimeSpan& TimeSpan);
  622.   CLTimeSpan EXPORT16 operator-(CLDate& ld);
  623.   CLDate     EXPORT16 operator-(const CLTimeSpan& TimeSpan);
  624.   CLDate&    EXPORT16 operator+=(const CLTimeSpan& TimeSpan);
  625.   CLDate&    EXPORT16 operator-=(const CLTimeSpan& TimeSpan);
  626.   CLDate&    EXPORT16 operator++();
  627.   CLDate&    EXPORT16 operator--();
  628.  
  629.  
  630.   //Overloaded Equality operators
  631.   BOOL EXPORT16 operator==(CLDate& ld);
  632.   BOOL EXPORT16 operator>(CLDate& ld);
  633.   BOOL EXPORT16 operator>=(CLDate& ld);
  634.   BOOL EXPORT16 operator<(CLDate& ld);
  635.   BOOL EXPORT16 operator<=(CLDate& ld);
  636.   BOOL EXPORT16 operator!=(CLDate& ld);
  637.  
  638.  
  639.   //Diagnostics / Debug
  640.   #ifdef _DEBUG
  641.   virtual void EXPORT16 AssertValid() const;
  642.   virtual void EXPORT16 Dump(CDumpContext& dc) const;
  643.   #endif
  644.  
  645.  
  646.   //Display
  647.   CString& EXPORT16 Format(const CString& sFormat=CLDate::GetDefaultFormat()) const;
  648.   
  649.  
  650.   //Serialization
  651.   virtual void EXPORT16 Serialize(CArchive& ar);
  652.  
  653.  
  654.   //streaming
  655.   friend ostream&  AFX_EXT_API EXPORT16 operator<<(ostream& os, const CLDate& LDate);
  656.   friend CArchive& AFX_EXT_API EXPORT16 operator<<(CArchive& ar, CLDate& LDate);
  657.   friend CArchive& AFX_EXT_API EXPORT16 operator>>(CArchive& ar, CLDate& LDate);
  658.   
  659.          
  660. protected:
  661.   void CheckForValidLocalDate();
  662.   BOOL DST();
  663.  
  664.  
  665.   double m_dSeconds;                 //Actual instance data
  666.   TimeFrame m_TimeFrame;             //What Time frame does this long date represent
  667.  
  668.   static CString sm_sBuffer;         //local Buffer for string return values
  669.   static CString sm_sDefaultFormat;  //Default Format string
  670.   static BOOL    sm_bDoAsserts;      //Asserts in constructors / castings, otherwise sets date to invalid date
  671.   static BOOL    sm_bIsDst;          //Used when determinf if the date is in DSTAsserts in constructors / castings, otherwise sets date to invalid date
  672. };
  673.  
  674. #endif //__DATE_H__
  675.  
  676.  
  677.  
  678.  
  679.                                         
  680.