00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef FXDATE_H
00024 #define FXDATE_H
00025
00026 namespace FX {
00027
00028
00029
00030
00031
00032
00033 class FXAPI FXDate {
00034 private:
00035 FXuint julian;
00036 private:
00037 static const FXchar shortMonthName[12][4];
00038 static const FXchar longMonthName[12][10];
00039 static const FXchar shortWeekDay[7][4];
00040 static const FXchar longWeekDay[7][10];
00041 public:
00042
00043
00044 enum {
00045 Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
00046 };
00047
00048
00049 enum {
00050 Sun=0,Mon,Tue,Wed,Thu,Fri,Sat
00051 };
00052
00053 public:
00054
00055
00056 FXDate(){}
00057
00058
00059 FXDate(const FXDate& date):julian(date.julian){}
00060
00061
00062 FXDate(FXuint jd):julian(jd){}
00063
00064
00065 FXDate(FXint yr,FXint dy);
00066
00067
00068 FXDate(FXint yr,FXint mo,FXint dy);
00069
00070
00071 void setJulian(FXuint jd){ julian=jd; }
00072
00073
00074 FXuint getJulian() const { return julian; }
00075
00076
00077 void setDate(FXint yr,FXint dy);
00078
00079
00080 void getDate(FXint& yr,FXint& dy) const;
00081
00082
00083 void setDate(FXint yr,FXint mo,FXint dy);
00084
00085
00086 void getDate(FXint& yr,FXint& mo,FXint& dy) const;
00087
00088
00089 void setTime(FXTime ns);
00090
00091
00092 FXTime getTime() const;
00093
00094
00095 FXint day() const;
00096
00097
00098 FXint month() const;
00099
00100
00101 FXint year() const;
00102
00103
00104 FXint dayOfWeek() const;
00105
00106
00107 FXint dayOfYear() const;
00108
00109
00110 FXint weekOfYear() const;
00111
00112
00113 FXbool leapYear() const;
00114
00115
00116 FXint daysInYear() const;
00117
00118
00119 FXint daysInMonth() const;
00120
00121
00122 FXDate& addDays(FXint d);
00123
00124
00125 FXDate& addMonths(FXint m);
00126
00127
00128 FXDate& addYears(FXint y);
00129
00130
00131 static FXbool leapYear(FXint yr);
00132
00133
00134 static FXint daysInYear(FXint yr);
00135
00136
00137 static FXint daysInMonth(FXint yr,FXint mo);
00138
00139
00140 static const FXchar *monthName(FXint mo){ return longMonthName[mo-1]; }
00141
00142
00143 static const FXchar *monthNameShort(FXint mo){ return shortMonthName[mo-1]; }
00144
00145
00146 static const FXchar *dayName(FXint dy){ return longWeekDay[dy]; }
00147
00148
00149 static const FXchar *dayNameShort(FXint dy){ return shortWeekDay[dy]; }
00150
00151
00152 static FXDate localDate();
00153
00154
00155 static FXDate universalDate();
00156
00157
00158 FXDate& operator=(const FXDate& date){julian=date.julian;return *this;}
00159
00160
00161 FXDate& operator+=(FXint x){ julian+=x; return *this; }
00162 FXDate& operator-=(FXint x){ julian-=x; return *this; }
00163
00164
00165 FXDate& operator++(){ ++julian; return *this; }
00166 FXDate& operator--(){ --julian; return *this; }
00167
00168
00169 FXDate operator++(int){ FXDate t(julian++); return t; }
00170 FXDate operator--(int){ FXDate t(julian--); return t; }
00171
00172
00173 FXbool operator==(const FXDate& date) const { return julian==date.julian;}
00174 FXbool operator!=(const FXDate& date) const { return julian!=date.julian;}
00175
00176
00177 FXbool operator<(const FXDate& date) const { return julian<date.julian;}
00178 FXbool operator<=(const FXDate& date) const { return julian<=date.julian;}
00179 FXbool operator>(const FXDate& date) const { return julian>date.julian;}
00180 FXbool operator>=(const FXDate& date) const { return julian>=date.julian;}
00181
00182
00183 friend inline FXDate operator+(const FXDate& d,FXint x);
00184 friend inline FXDate operator+(FXint x,const FXDate& d);
00185
00186
00187 friend inline FXint operator-(const FXDate& a,const FXDate& b);
00188
00189
00190 friend FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
00191
00192
00193 friend FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
00194 };
00195
00196
00197 inline FXDate operator+(const FXDate& d,FXint x){ return FXDate(d.julian+x); }
00198 inline FXDate operator+(FXint x,const FXDate& d){ return FXDate(x+d.julian); }
00199 inline FXint operator-(const FXDate& a,const FXDate& b){return a.julian-b.julian; }
00200
00201 extern FXAPI FXStream& operator<<(FXStream& store,const FXDate& d);
00202 extern FXAPI FXStream& operator>>(FXStream& store,FXDate& d);
00203
00204 }
00205
00206 #endif