00001
00002
00003 #ifndef BASE_DATETIME_H
00004 #define BASE_DATETIME_H
00005
00006 #include "String.h"
00007
00008 namespace base {
00010
00019 class PPBASE_EXPORT DateTime {
00020 public:
00022 DateTime();
00023
00025
00029 DateTime(const String &s, bool utc = false);
00030
00032
00035 void addDays(int n);
00036
00038
00041 void addHours(int n);
00042
00044
00047 void addMinutes(int n);
00048
00050
00053 void addMonths(int n);
00054
00056
00059 void addSeconds(int n);
00060
00062
00065 void addYears(int n);
00066
00068
00075 static int compare(const DateTime &lhs, const DateTime &rhs, bool time = true, bool millis = true);
00076
00078
00083 static int compareDate(const DateTime &lhs, const DateTime &rhs);
00084
00086
00092 static int compareTime(const DateTime &lhs, const DateTime &rhs, bool millis = true);
00093
00095
00107 static bool diff(const DateTime &lhs, const DateTime &rhs, unsigned *rdays, unsigned char *rhours = NULL,
00108 unsigned char *rminutes = NULL, unsigned char *rseconds = NULL, unsigned short *rmillis = NULL);
00109
00111
00118 static int diffSeconds(const DateTime &lhs, const DateTime &rhs);
00119
00121
00124 unsigned char getDay() const;
00125
00127
00130 unsigned char getDayOfWeek() const;
00131
00133
00139 static unsigned getDayOfYear(unsigned char day, unsigned char month, short year);
00140
00142
00145 unsigned getDayOfYear() const;
00146
00148
00151 unsigned char getHour() const;
00152
00154
00157 unsigned getMilliSecondOfDay() const;
00158
00160
00163 unsigned short getMilliSeconds() const;
00164
00166
00169 unsigned char getMinute() const;
00170
00172
00175 unsigned char getMonth() const;
00176
00178
00181 unsigned char getMonthDays() const;
00182
00184
00189 static unsigned char getMonthDays(unsigned char month, short year);
00190
00192
00195 unsigned char getSecond() const;
00196
00198
00201 unsigned getSecondOfDay() const;
00202
00204
00207 short getYear() const;
00208
00210
00213 unsigned short getYearDays() const;
00214
00216
00220 static unsigned short getYearDays(short year);
00221
00223
00226 bool isLeapYear() const;
00227
00229
00233 static bool isLeapYear(short year);
00234
00236
00239 bool isNull() const;
00240
00242
00245 bool isUTC() const;
00246
00248 void nextDay();
00249
00251 void nextHour();
00252
00254 void nextMinute();
00255
00257 void nextMonth();
00258
00260 void nextYear();
00261
00263 void prevDay();
00264
00266 void prevHour();
00267
00269 void prevMinute();
00270
00272 void prevMonth();
00273
00275 void prevYear();
00276
00278
00283 bool set(const String &str, bool utc = false);
00284
00286
00290 void setCurrent(bool utc = false, bool millis = false);
00291
00293
00298 void setDate(unsigned char day, unsigned char month, short year);
00299
00301
00304 void setUTC(bool utc);
00305
00307
00313 void setTime(unsigned char hour, unsigned char minute, unsigned char second, unsigned short millis = 0);
00314
00316
00320 String toString(const char *format = NULL) const;
00321
00323
00326 bool valid() const;
00327
00329
00332 void operator=(const String &s);
00333
00335
00338 bool operator!() const;
00339
00341
00345 bool operator==(const DateTime &d) const;
00346
00348
00352 bool operator!=(const DateTime &d) const;
00353
00355
00359 bool operator<(const DateTime &d) const;
00360
00362
00366 bool operator<=(const DateTime &d) const;
00367
00369
00373 bool operator>(const DateTime &d) const;
00374
00376
00380 bool operator>=(const DateTime &d) const;
00381
00382 private:
00384 void calculateDayOfWeek();
00385
00386 unsigned char _hour;
00387 unsigned char _minute;
00388 unsigned char _second;
00389 unsigned char _day;
00390 unsigned char _dow;
00391 unsigned char _month;
00392 short _year;
00393 unsigned short _millis;
00394 bool _utc;
00395 };
00396 }
00397
00398 #endif