Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

SimpleDate.h

Go to the documentation of this file.
00001 /********************************************************************
00002        Copyright (c) 2001, Lee Patterson & Ant Works Software
00003        http://ssobjects.sourceforge.net
00004 
00005        Original source from http://www.codeproject.com/datetime/dateclass.asp
00006        Copyright (c), Richard Stringer
00007 
00008        filename : SimpleDate.h
00009 
00010        changes  : 24-AUG-2000 Lee Patterson (lee@antws.com)
00011                   - Removed MFC code so it will compile under other 
00012                     platforms.
00013                   - Made more functions use const.
00014 
00015        notes    : Most of the date alogrithms used in this class 
00016                   can be found at:
00017                   http://www.capecod.net/~pbaum/date/date0.htm
00018 
00019 *********************************************************************/
00020 
00021 #ifndef SIMPLEDATE_H
00022 #define SIMPLEDATE_H
00023 
00024 namespace ssobjects
00025 {
00026 
00027 enum{
00028     MMDDYY,
00029     DDMMYY,
00030     YYMMDD,
00031     MMDDYYYY,
00032     DDMMYYYY,
00033     YYYYMMDD,
00034 };
00035 
00036 // NOTE:: If you choose any of the two digit year formats you had better be sure all
00037 //        dates will be in the range of 1900-1999 else there will be unexpected results
00038 
00039 #ifdef WIN32
00040 # define snprintf _snprintf             //make it linux like (NOTE: snprintf in Linux behaives a little different when you exceed the size
00041 #else
00042  typedef const char* LPCSTR;
00043  typedef char* LPSTR;
00044 #endif
00045 
00046 class CSimpleDate  
00047 {
00048 public:
00049     //  constructors and destructors
00050     CSimpleDate(int FormatType=MMDDYYYY);
00051     CSimpleDate(LPCSTR DateString,int FormatType=MMDDYYYY);
00052     CSimpleDate(long JD,int FormatType=MMDDYYYY);
00053     virtual ~CSimpleDate();
00054 
00055     //  Date math routines
00056     const   CSimpleDate& AddDays(int Days);
00057     const   CSimpleDate& AddYears(int Yrs);
00058     const   CSimpleDate& AddMonths(int Mon);
00059     const   CSimpleDate& SubtractYears(int Yrs);
00060     const   CSimpleDate& SubtractDays(int Days);
00061     const   CSimpleDate& SubtractMonths(int Mon);
00062     virtual int         YearsOld();
00063 
00064     // access routines;
00065     LPCSTR      GetFullDateString();
00066     LPCSTR      GetFullDateStringLong();
00067     virtual     int GetDayOfWeek();
00068     virtual     bool IsValid() const;
00069     long        GetJulianDate(); // easier to use (long)CSimpelDate but some prefer this
00070 
00071     virtual     int GetDay()
00072                     {if(!IsValid()) return 0;return m_Day;};
00073     virtual     int GetMonth()
00074                     {if(!IsValid()) return 0;return m_Month;};
00075     virtual     int GetYear()
00076                     {if(!IsValid()) return 0;return m_Year;};
00077     virtual     void    GetIntegerDate(int& m, int& d,int& y)
00078                     {if(!IsValid()) return;m=m_Month;y=m_Year;d=m_Day;};
00079     virtual     int     GetHour()
00080                     {if(!IsValid()) return 0;return m_Hour+m_bPM*12;};
00081     virtual     int     GetMin()
00082                     {if(!IsValid()) return 0;return m_Min;};
00083     virtual     int     GetSeconds()
00084                     {if(!IsValid()) return 0;return m_Second;};
00085 
00086     virtual     void    GetTimeString(LPSTR s,int nLen,bool AmPm=true);
00087     virtual     void    GetTimeStringShort(LPSTR s,int nLen,bool AmPm=true);
00088 
00089     //  operator assignments conversions equality etc...
00090     operator    LPCSTR();
00091     operator    long() const;
00092     const CSimpleDate& operator = (const CSimpleDate& Date);
00093     const CSimpleDate& operator = (LPCSTR Date);
00094     bool operator > (const CSimpleDate& Date) const;
00095     bool operator < (const CSimpleDate& Date) const;
00096     bool operator >= (const CSimpleDate& Date) const;
00097     bool operator <= (const CSimpleDate& Date) const;
00098     bool operator == (const CSimpleDate& Date) const;
00099     bool operator != (const CSimpleDate& Date) const;
00100     bool operator > (LPCSTR Date) const;
00101     bool operator < (LPCSTR Date) const;
00102     bool operator >= (LPCSTR Date) const;
00103     bool operator <= (LPCSTR Date) const;
00104     bool operator == (LPCSTR Date) const;
00105     bool operator != (LPCSTR Date) const;
00106 
00107 
00108 
00109 protected:
00110     //  internal class stuff
00111     virtual bool    SetToday();
00112     virtual bool    CSimpleDate::ParseDateString(LPCSTR,int& m,int& d,int& y);
00113     virtual bool    ParseDateString(LPCSTR);
00114     virtual long    ConvertToJulian( int month,int day,int year);
00115     virtual long    ConvertToJulian();
00116     virtual void    ConvertFromJulian(int& Month,int& Day,int& Year);
00117     virtual void    ConvertFromJulian();
00118     virtual void    AdjustDays();
00119     virtual void SetTime();
00120 
00121     //  STATIC MEMBER FUNCTIONS
00122 public:  
00123     
00124     // the static functions assume a date format of MMDDYY or MMDDYYYY
00125     //  They also do not call this IsValid() function
00126     static  bool    VerifyDateFormat(LPCSTR date);
00127     static  bool    FixDateFormat(LPSTR date);
00128     
00129 
00130     //  class data
00131 protected:
00132     int         m_Year;
00133     int         m_Month;
00134     int         m_Day;
00135     long        m_JulianDate;
00136     int         m_Format;
00137     char        m_DateString[80];
00138 
00139     int         m_Hour;
00140     int         m_Min;
00141     int         m_Second;
00142     bool        m_bPM;
00143 
00144 };
00145 
00146 };
00147 
00148 #endif  //SIMPLEDATE_H
00149 

Generated on Thu Nov 8 12:39:26 2001 for SimpleServerObjects by doxygen1.2.11 written by Dimitri van Heesch, © 1997-2001