Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXDate.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                            D a t e   C l a s s                                *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2005,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXDATE_H
00022 #define FXDATE_H
00023 
00024 namespace FX {
00025 
00026 
00027 
00031 class FXAPI FXDate {
00032 private:
00033   FXuint julian;
00034 private:
00035   static const FXchar shortMonthName[12][4];
00036   static const FXchar longMonthName[12][10];
00037   static const FXchar shortWeekDay[7][4];
00038   static const FXchar longWeekDay[7][10];
00039 public:
00040 
00042   enum {
00043     Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
00044     };
00045 
00047   enum {
00048     Sun=0,Mon,Tue,Wed,Thu,Fri,Sat
00049     };
00050 
00051 public:
00052 
00054   FXDate(){}
00055 
00057   FXDate(const FXDate& date):julian(date.julian){}
00058 
00060   FXDate(FXuint jd):julian(jd){}
00061 
00063   FXDate(FXint yr,FXint dy);
00064 
00066   FXDate(FXint yr,FXint mo,FXint dy);
00067 
00069   void setJulian(FXuint jd){ julian=jd; }
00070 
00072   FXuint getJulian() const { return julian; }
00073 
00075   void setDate(FXint yr,FXint dy);
00076 
00078   void getDate(FXint& yr,FXint& dy) const;
00079 
00081   void setDate(FXint yr,FXint mo,FXint dy);
00082 
00084   void getDate(FXint& yr,FXint& mo,FXint& dy) const;
00085 
00087   void setTime(FXTime ns);
00088 
00090   FXTime getTime() const;
00091 
00093   FXint day() const;
00094 
00096   FXint month() const;
00097 
00099   FXint year() const;
00100 
00102   FXint dayOfWeek() const;
00103 
00105   FXint dayOfYear() const;
00106 
00108   FXint weekOfYear() const;
00109 
00111   FXbool leapYear() const;
00112 
00114   FXint daysInYear() const;
00115 
00117   FXint daysInMonth() const;
00118 
00120   FXDate& addDays(FXint d);
00121 
00123   FXDate& addMonths(FXint m);
00124 
00126   FXDate& addYears(FXint y);
00127 
00129   static FXbool leapYear(FXint yr);
00130 
00132   static FXint daysInYear(FXint yr);
00133 
00135   static FXint daysInMonth(FXint yr,FXint mo);
00136 
00138   static const FXchar *monthName(FXint mo){ return longMonthName[mo-1]; }
00139 
00141   static const FXchar *monthNameShort(FXint mo){ return shortMonthName[mo-1]; }
00142 
00144   static const FXchar *dayName(FXint dy){ return longWeekDay[dy]; }
00145 
00147   static const FXchar *dayNameShort(FXint dy){ return shortWeekDay[dy]; }
00148 
00150   static FXDate localDate();
00151 
00153   static FXDate universalDate();
00154 
00156   FXDate& operator=(const FXDate& date){julian=date.julian;return *this;}
00157 
00159   FXDate& operator+=(FXint x){ julian+=x; return *this; }
00160   FXDate& operator-=(FXint x){ julian-=x; return *this; }
00161 
00163   FXDate& operator++(){ ++julian; return *this; }
00164   FXDate& operator--(){ --julian; return *this; }
00165 
00167   FXDate operator++(int){ FXDate t(julian++); return t; }
00168   FXDate operator--(int){ FXDate t(julian--); return t; }
00169 
00171   FXbool operator==(const FXDate& date) const { return julian==date.julian;}
00172   FXbool operator!=(const FXDate& date) const { return julian!=date.julian;}
00173 
00175   FXbool operator<(const FXDate& date) const { return julian<date.julian;}
00176   FXbool operator<=(const FXDate& date) const { return julian<=date.julian;}
00177   FXbool operator>(const FXDate& date) const { return julian>date.julian;}
00178   FXbool operator>=(const FXDate& date) const { return julian>=date.julian;}
00179 
00181   friend inline FXDate operator+(const FXDate& d,FXint x);
00182   friend inline FXDate operator+(FXint x,const FXDate& d);
00183 
00185   friend inline FXint operator-(const FXDate& a,const FXDate& b);
00186 
00188   friend FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
00189 
00191   friend FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
00192   
00194  ~FXDate(){}
00195   };
00196 
00197 
00198 inline FXDate operator+(const FXDate& d,FXint x){ return FXDate(d.julian+x); }
00199 inline FXDate operator+(FXint x,const FXDate& d){ return FXDate(x+d.julian); }
00200 inline FXint operator-(const FXDate& a,const FXDate& b){return a.julian-b.julian; }
00201 
00202 extern FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
00203 extern FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
00204 
00205 }
00206 
00207 #endif

Copyright © 1997-2011 Jeroen van der Zijp