FXDate.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                            D a t e   C l a s s                                *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2005,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXDate.h,v 1.10.2.1 2006/07/17 17:57:30 fox Exp $                            *
00023 ********************************************************************************/
00024 #ifndef FXDATE_H
00025 #define FXDATE_H
00026 
00027 namespace FX {
00028 
00029 
00030 
00034 class FXAPI FXDate {
00035 private:
00036   FXuint julian;
00037 private:
00038   static const FXchar shortMonthName[12][4];
00039   static const FXchar longMonthName[12][10];
00040   static const FXchar shortWeekDay[7][4];
00041   static const FXchar longWeekDay[7][10];
00042 protected:
00043   static void greg2jul(FXuint& jd,FXint y,FXint m,FXint d);
00044   static void jul2greg(FXuint jd,FXint& y,FXint& m,FXint& d);
00045 public:
00046 
00048   enum {
00049     Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
00050     };
00051 
00053   enum {
00054     Sun=0,Mon,Tue,Wed,Thu,Fri,Sat
00055     };
00056 
00057 public:
00058 
00060   FXDate(){}
00061 
00063   FXDate(const FXDate& date):julian(date.julian){}
00064 
00066   FXDate(FXint y,FXint m,FXint d);
00067 
00069   FXDate(FXuint j):julian(j){}
00070 
00072   void setJulian(FXuint d){ julian=d; }
00073 
00075   FXuint getJulian() const { return julian; }
00076 
00078   void setDate(FXint y,FXint m,FXint d);
00079 
00081   void getDate(FXint& y,FXint& m,FXint& d) const;
00082 
00084   FXint day() const;
00085 
00087   FXint month() const;
00088 
00090   FXint year() const;
00091 
00093   FXint dayOfWeek() const;
00094 
00096   FXint dayOfYear() const;
00097 
00099   FXint daysInMonth() const;
00100 
00102   bool leapYear() const;
00103 
00105   static bool leapYear(FXint y);
00106 
00108   static const FXchar *monthName(FXint m){ return longMonthName[m-1]; }
00109 
00111   static const FXchar *monthNameShort(FXint m){ return shortMonthName[m-1]; }
00112 
00114   static const FXchar *dayName(FXint d){ return longWeekDay[d]; }
00115 
00117   static const FXchar *dayNameShort(FXint d){ return shortWeekDay[d]; }
00118 
00120   static FXDate localDate();
00121 
00123   static FXDate zuluDate();
00124 
00126   FXDate& operator=(const FXDate& date){julian=date.julian;return *this;}
00127 
00129   FXDate& operator+=(FXint x){ julian+=x; return *this; }
00130   FXDate& operator-=(FXint x){ julian-=x; return *this; }
00131 
00133   FXDate& operator++(){ julian++; return *this; }
00134   FXDate& operator--(){ julian--; return *this; }
00135 
00137   bool operator==(const FXDate& date) const { return julian==date.julian;}
00138   bool operator!=(const FXDate& date) const { return julian!=date.julian;}
00139 
00141   bool operator<(const FXDate& date) const { return julian<date.julian;}
00142   bool operator<=(const FXDate& date) const { return julian<=date.julian;}
00143   bool operator>(const FXDate& date) const { return julian>date.julian;}
00144   bool operator>=(const FXDate& date) const { return julian>=date.julian;}
00145 
00147   friend inline FXDate operator+(const FXDate& d,FXint x);
00148   friend inline FXDate operator+(FXint x,const FXDate& d);
00149 
00151   friend inline FXint operator-(const FXDate& a,const FXDate& b);
00152 
00154   friend FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
00155 
00157   friend FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
00158   };
00159 
00160 
00161 inline FXDate operator+(const FXDate& d,FXint x){ return FXDate(d.julian+x); }
00162 inline FXDate operator+(FXint x,const FXDate& d){ return FXDate(x+d.julian); }
00163 inline FXint operator-(const FXDate& a,const FXDate& b){return a.julian-b.julian; }
00164 
00165 extern FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
00166 extern FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
00167 
00168 }
00169 
00170 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:20 2009 for TnFOX by doxygen v1.4.7