00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _SWORD_TIME_DATE_
00020 #define _SWORD_TIME_DATE_
00021
00022 #include "sword/time.Time.h"
00023 #include "sword/time.CalendarWestern.h"
00024 #include "sword/time.CalendarGregorian.h"
00025
00026 namespace sword {
00027
00029 class SWORDDECL Date : public Comparable<Date> {
00030 public:
00032 Date() throw();
00033
00035 Date(const Date &rhs) throw();
00036
00038 Date &operator=(const Date &rhs) throw();
00039
00041 Date(word day, word month, word year, word hour, word minute, word second, word millis, const Calendar &calendar) throw();
00042
00044
00045 Date(word day, word month, word year, word hour, word minute, word second, word millis) throw();
00046
00048
00050 Date(word day, word month, word year, const Calendar &calendar) throw();
00051
00053
00056 Date(word day, word month, word year) throw();
00057
00059 Date(Time time, const Calendar &calendar);
00060
00062
00064 Date(Time time);
00065
00067 Date(int packed, const Calendar &calendar);
00068
00070
00072 Date(int packed);
00073
00075
00077 static Date now(const Calendar &calendar);
00078
00080
00083 static Date now();
00084
00086
00088 static Date nowUTC(const Calendar &calendar);
00089
00091
00094 static Date nowUTC();
00095
00096
00097
00099 word day() const throw();
00100
00102 word month() const throw();
00103
00105 word year() const throw();
00106
00108 word hour() const throw();
00109
00111 word minute() const throw();
00112
00114 word second() const throw();
00115
00117 word millis() const throw();
00118
00120 const Calendar& calendar() const throw();
00121
00122
00123
00125
00128 word weekDay() const;
00129
00131 word weekNumber() const;
00132
00134 word dayWithinYear() const;
00135
00136
00137
00139 void day(word value) throw();
00140
00142 void month(word value) throw();
00143
00145 void year(word value) throw();
00146
00148 void hour(word value) throw();
00149
00151 void minute(word value) throw();
00152
00154 void second(word value) throw();
00155
00157 void millis(word value) throw();
00158
00159
00160
00162 bool empty() const throw();
00163
00165 void clear() throw();
00166
00168 void set(word day, word month, word year, word hour, word minute, word second, word millis, const Calendar &calendar) throw();
00169
00171 void set(word day, word month, word year, const Calendar &calendar) throw();
00172
00173
00174
00176
00183 void addYears(int years, bool endToEnd = false);
00184
00186
00191 void addMonths(int months, bool endToEnd = false);
00192
00194 void addDays(int days);
00195
00197 void addHours(int hours);
00198
00200 void addMinutes(int minutes);
00201
00203 void addSeconds(int seconds);
00204
00206 void addMillis(int millis);
00207
00209 void next();
00210
00212 void prev();
00213
00214
00215
00217 void fromTime(Time time, const Calendar &calendar);
00218
00220
00222 void fromTime(Time time);
00223
00225 Time toTime() const;
00226
00228 void fromPackedDate(int packed, const Calendar &calendar);
00229
00231 void fromPackedDate(int packed);
00232
00234 int toPackedDate() const;
00235
00237 bool valid() const;
00238
00239
00240
00242
00270 std::string toString(const std::string &format) const;
00271
00273
00277 void fromString(const std::string &format, const std::string &data);
00278
00279
00280 static const char *formatRFC822UTC;
00281 static const char *formatRFC822;
00282
00284 static int compare(const Date &lhs, const Date &rhs);
00285
00286
00287
00288 class FormatException : public Exception {};
00289 class RangeException : public Exception {};
00290
00291 private:
00292 word day_;
00293 word month_;
00294 word year_;
00295 word hour_;
00296 word minute_;
00297 word second_;
00298 word millis_;
00299 Calendar &calendar_;
00300
00301
00302
00303 int64 pseudoSerial_() const;
00304 };
00305
00306 }
00307
00308 #include "sword.private/time.Date.inl"
00309
00310 #endif // _SWORD_TIME_DATE_