Xbase64 Class Library  3.1.2
xbdate.h
Go to the documentation of this file.
00001 /*  xbdate.h
00002 
00003     Xbase64 project source code
00004 
00005     This file contains a header file for the xbDate object, which is 
00006     used for handling dates.
00007 
00008     Copyright (C) 1997,2003  Gary A Kunkel
00009     
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 
00024 
00025     Contact:
00026     
00027      Email:
00028     
00029       xdb-devel@lists.sourceforge.net
00030       xdb-users@lists.sourceforge.net
00031       
00032       
00033      Regular Mail:
00034      
00035        XBase Support
00036        149C South Main St
00037        Keller Texas, 76248     
00038        USA
00039 
00040 */
00041 
00045 #ifndef __XB_XBDATE_H__
00046 #define __XB_XBDATE_H__
00047 
00048 #ifdef __GNU_LesserG__
00049 #pragma interface
00050 #endif
00051 
00052 #ifdef __WIN32__
00053 #include <xbase64/xbwincfg.h>
00054 #else
00055 #include <xbase64/xbconfig.h>
00056 #endif
00057 
00058 #include <xbase64/xbstring.h>
00059 
00060 #define XB_FMT_WEEK   1
00061 #define XB_FMT_MONTH  2
00062 #define XB_FMT_YEAR   3
00063 
00065 
00068 class XBDLLEXPORT xbDate {
00069   public:
00070     xbDate();
00071     xbDate( const char * Date8 );
00072     xbDate( const xbString &Date8 );
00073     virtual ~xbDate();
00074 
00076 
00078     const xbString & GetDate() const 
00079       { return cDate8; };
00081 
00083     xbString & GetDate() 
00084       { return cDate8; };
00086 
00088     const xbString & GetFormattedDate() const 
00089       { return fDate; };
00091 
00093     xbString & GetFormattedDate() 
00094       { return fDate; };
00095 
00096     int SetDate( const char * Date8 );
00098 
00100     int SetDate( const xbString & Date8 )
00101          { return SetDate((const char *) Date8 ); };
00102 
00103     long JulianDays    ( const char *Date8 ) const;
00105 
00107     long JulianDays    ( const xbString & Date8 ) const
00108          { return JulianDays((const char *) Date8 ); };
00110 
00112     long JulianDays    () const
00113          { return JulianDays((const char *) cDate8 ); };
00114 
00115     int  YearOf        ( const char *Date8 ) const;
00117 
00119     int  YearOf        ( const xbString & Date8 ) const
00120          { return YearOf((const char *) Date8 ); };
00122 
00124     int  YearOf        () const
00125          { return YearOf((const char *) cDate8 ); };
00126 
00128 
00130     int  CenturyOf     ( const char *Date8 ) const;
00131 
00132     int  MonthOf       ( const char *Date8 ) const;
00134 
00136     int  MonthOf       ( const xbString &Date8 ) const
00137          { return MonthOf((const char *) Date8 ); };
00139 
00141     int  MonthOf       () const
00142          { return MonthOf(( const char *) cDate8 ); };
00143     
00144     int  DayOf         ( int Format, const char *Date8 ) const;
00146 
00148     int  DayOf         ( int Format, const xbString &Date8 ) const
00149          { return DayOf( Format, (const char *) Date8 ); };
00151 
00153     int  DayOf         ( int Format ) const
00154          { return DayOf( Format, (const char *) cDate8 ); };
00155     
00156     int  IsLeapYear    ( const char *Date8 ) const;
00158 
00160     int  IsLeapYear    ( const xbString &Date8 ) const
00161          { return IsLeapYear((const char *) Date8 ); };
00163 
00165     int  IsLeapYear    () const
00166          { return IsLeapYear((const char *) cDate8 ); };
00167 
00169 
00171     int  CalcRollingCenturyForYear( int ) const;
00172     
00173 
00174     int  DateIsValid   ( const char *Date8 ) const;
00176 
00178     int  DateIsValid   ( const xbString & Date8 ) const
00179          { return DateIsValid( (const char *) Date8 ); };
00180     
00181     xbString& LastDayOfMonth( const char *Date8 );
00183 
00185     xbString& LastDayOfMonth( const xbString & Date8 )
00186          { return LastDayOfMonth((const char *) Date8 ); };
00188 
00190     xbString& LastDayOfMonth()
00191          { return LastDayOfMonth((const char *) cDate8 ); };
00192 
00193     xbString& Sysdate   ();
00194     xbString& JulToDate8( long );
00195 
00197 
00199     xbString& FormatCTODdate( const char * indate );
00200 
00202 
00204     xbString& FormatDate( const char *Format, const char *Date8 );
00206 
00208     xbString& FormatDate( const xbString &Format, const char *Date8 )
00209      { return FormatDate((const char *) Format, Date8 ); };
00211 
00213     xbString& FormatDate( const char *Format, const xbString &Date8 )
00214      { return FormatDate( Format, (const char *) Date8 ); };
00216 
00218     xbString& FormatDate( const xbString &Format, const xbString &Date8 )
00219      { return FormatDate((const char *) Format,(const char *) Date8 ); };
00221 
00223     xbString& FormatDate( const char *Format )
00224      { return FormatDate( (const char *) Format, (const char *) cDate8 ); };
00226 
00228     xbString& FormatDate( const xbString &Format )
00229      { return FormatDate((const char *) Format, (const char *) cDate8 ); };
00230     
00231     xbString& CharDayOf ( const char *Date8 );
00233 
00235     xbString& CharDayOf ( const xbString &Date8 )
00236       { return CharDayOf((const char *) Date8 ); };
00238 
00240     xbString& CharDayOf ()
00241       { return CharDayOf((const char *) cDate8 ); };
00242 
00243     xbString& CharMonthOf ( const char *Date8 );
00245 
00247     xbString& CharMonthOf ( const xbString &Date8 )
00248       { return CharMonthOf(( const char *) Date8 ); };
00250 
00252     xbString& CharMonthOf ()
00253       { return CharMonthOf(( const char *) cDate8 ); };
00254 
00255     xbString &operator+=( int );
00256     xbString &operator-=( int );
00257     xbString &operator++( int );              /* post increment */
00258     xbString &operator--( int );              /* post increment */
00259     xbString &operator+ ( int );
00260     xbString &operator- ( int );
00261     long operator-( const xbDate & ) const;
00262     int operator==( const xbDate & ) const;
00263     int operator!=( const xbDate & ) const;
00264     int operator< ( const xbDate & ) const;
00265     int operator> ( const xbDate & ) const;
00266     int operator<=( const xbDate & ) const;
00267     int operator>=( const xbDate & ) const;
00268 
00269   protected:
00270     void SetDateTables();
00271     xbString cDate8;  /* CCYYMMDD date format */
00272     xbString fDate;   /* other date format    */
00273     static int AggregatedDaysInMonths[2][13];
00274     static int DaysInMonths[2][13];
00275 };    
00276 
00277 #endif    // __XB_XBDATE_H__
00278