00001
00002
00003 #ifndef __DATE_TIME_H
00004 #define __DATE_TIME_H
00005
00006 #include <time.h>
00007
00008 #define GDTF_DEFAULT 0
00009
00011 #define GDTF_DAY_MONTH_YEAR 0x001
00013 #define GDTF_MONTH_DAY_YEAR 0x002
00015 #define GDTF_YEAR_MONTH_DAY 0x004
00016 #define GDTF_DATE_MASK 0x00f
00017
00019 #define GDTF_12HOUR 0x010
00021 #define GDTF_24HOUR 0x020
00022 #define GDTF_TIME_MASK 0x0f0
00023
00025 #define GDTF_DAY_LEADINGZ 0x100
00027 #define GDTF_MONTH_LEADINGZ 0x200
00028
00039 class LgiClass GDateTime
00040 {
00042 int16 _Day;
00044 int16 _Year;
00046 int16 _Thousands;
00047
00049 int16 _Month;
00051 int16 _Seconds;
00053 int16 _Minutes;
00055 int16 _Hours;
00056
00058 int16 _Tz;
00059
00061 uint16 _Format;
00063 static uint16 DefaultFormat;
00065 static char DefaultSeparator;
00066
00067 public:
00068 GDateTime();
00069 ~GDateTime();
00070
00071 enum
00072 {
00075 #ifdef WIN32
00076 Second64Bit = 10000000,
00077 #else
00078 Second64Bit = 1000,
00079 #endif
00080 };
00081
00083 bool IsValid();
00084
00086 int Day() { return _Day; }
00088 void Day(int d) { _Day = d; }
00090 int Month() { return _Month; }
00092 void Month(int m) { _Month = m; }
00094 void Month(char *m);
00096 int Year() { return _Year; }
00098 void Year(int y) { _Year = y; }
00099
00101 int Thousands() { return _Thousands; }
00103 void Thousands(int t) { _Thousands = t; }
00105 int Seconds() { return _Seconds; }
00107 void Seconds(int s) { _Seconds = s; }
00109 int Minutes() { return _Minutes; }
00111 void Minutes(int m) { _Minutes = m; }
00113 int Hours() { return _Hours; }
00115 void Hours(int h) { _Hours = h; }
00116
00118 int GetTimeZone() { return _Tz; }
00120 void SetTimeZone
00121 (
00123 int Tz,
00126 bool ConvertTime
00127 );
00130 void ToUtc() { SetTimeZone(0, true); }
00133 void ToLocal() { SetTimeZone(SystemTimeZone(), true); }
00134
00138 uint16 GetFormat() { return _Format; }
00141 void SetFormat
00142 (
00144 uint16 f
00145 ) { _Format = f; }
00147 static uint16 GetDefaultFormat();
00149 static void SetDefaultFormat(uint16 f) { DefaultFormat = f; }
00150
00152 int DayOfWeek();
00153
00156 void Get(char *Str);
00158 bool Get(uint64 &s);
00161 void GetDate(char *Str);
00164 void GetTime(char *Str);
00165
00167 void SetNow();
00170 bool Set(const char *Str);
00172 bool Set(uint64 s);
00174 bool Set(time_t tt);
00177 bool SetDate(const char *Str);
00180 bool SetTime(const char *Str);
00181
00183 bool IsLeapYear
00184 (
00186 int Year = -1
00187 );
00189 bool IsSameDay(GDateTime &d);
00191 int DaysInMonth();
00192
00194 void AddSeconds(int64 Seconds);
00196 void AddMinutes(int Minutes);
00198 void AddHours(int Hours);
00200 void AddDays(int Days);
00202 void AddMonths(int Months);
00203
00205 static int SystemTimeZone(bool ForceUpdate = false);
00208 static int SystemTimeZoneOffset();
00209
00211 struct LgiClass GDstInfo
00212 {
00214 int64 UtcTimeStamp;
00216 int Offset;
00217
00218 GDateTime GetLocal();
00219 };
00220
00224 static bool
00225 GetDaylightSavingsInfo
00226 (
00229 GArray<GDstInfo> &Out,
00231 GDateTime &Start,
00233 GDateTime *End = 0
00234 );
00235
00236
00237 int Sizeof();
00238 bool Serialize(class GFile &f, bool Write);
00239 bool Serialize(class GDom *Props, char *Name, bool Write);
00240
00241
00242 bool operator <(GDateTime &dt);
00243 bool operator <=(GDateTime &dt);
00244 bool operator >(GDateTime &dt);
00245 bool operator >=(GDateTime &dt);
00246 bool operator ==(GDateTime &dt);
00247 bool operator !=(GDateTime &dt);
00248 int Compare(GDateTime *d);
00249
00250 GDateTime operator -(GDateTime &dt);
00251 GDateTime operator +(GDateTime &dt);
00252 GDateTime DiffMonths(GDateTime &dt);
00253
00254 operator uint64()
00255 {
00256 uint64 ts = 0;
00257 Get(ts);
00258 return ts;
00259 }
00260
00261 GDateTime &operator =(uint64 ts)
00262 {
00263 Set(ts);
00264 return *this;
00265 }
00266 };
00267
00269 struct GTimeZone
00270 {
00271 public:
00273 float Offset;
00275 char *Text;
00276 };
00277
00279 extern GTimeZone GTimeZones[];
00280
00281 #endif