00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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