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
00031
00032
00033
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
00047
00048 enum {
00049 Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
00050 };
00051
00052
00053 enum {
00054 Sun=0,Mon,Tue,Wed,Thu,Fri,Sat
00055 };
00056
00057 public:
00058
00059
00060 FXDate(){}
00061
00062
00063 FXDate(const FXDate& date):julian(date.julian){}
00064
00065
00066 FXDate(FXint y,FXint m,FXint d);
00067
00068
00069 FXDate(FXuint j):julian(j){}
00070
00071
00072 void setJulian(FXuint day){ julian=day; }
00073
00074
00075 FXuint getJulian() const { return julian; }
00076
00077
00078 void setDate(FXint y,FXint m,FXint d);
00079
00080
00081 void getDate(FXint& y,FXint& m,FXint& d) const;
00082
00083
00084 FXint day() const;
00085
00086
00087 FXint month() const;
00088
00089
00090 FXint year() const;
00091
00092
00093 FXint dayOfWeek() const;
00094
00095
00096 FXint dayOfYear() const;
00097
00098
00099 FXint daysInMonth() const;
00100
00101
00102 bool leapYear() const;
00103
00104
00105 static bool leapYear(FXint y);
00106
00107
00108 static const FXchar *monthName(FXint month){ return longMonthName[month-1]; }
00109
00110
00111 static const FXchar *monthNameShort(FXint month){ return shortMonthName[month-1]; }
00112
00113
00114 static const FXchar *dayName(FXint day){ return longWeekDay[day]; }
00115
00116
00117 static const FXchar *dayNameShort(FXint day){ return shortWeekDay[day]; }
00118
00119
00120 static FXDate localDate();
00121
00122
00123 static FXDate zuluDate();
00124
00125
00126 FXDate& operator=(const FXDate& date){julian=date.julian;return *this;}
00127
00128
00129 FXDate& operator+=(FXint x){ julian+=x; return *this; }
00130 FXDate& operator-=(FXint x){ julian-=x; return *this; }
00131
00132
00133 FXDate& operator++(){ julian++; return *this; }
00134 FXDate& operator--(){ julian--; return *this; }
00135
00136
00137 bool operator==(const FXDate& date) const { return julian==date.julian;}
00138 bool operator!=(const FXDate& date) const { return julian!=date.julian;}
00139
00140
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
00146
00147 friend inline FXDate operator+(const FXDate& d,FXint x);
00148 friend inline FXDate operator+(FXint x,const FXDate& d);
00149
00150
00151 friend inline FXint operator-(const FXDate& a,const FXDate& b);
00152
00153
00154 friend FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
00155
00156
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