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
00034 class LgiClass GDateTime
00035 {
00037 int16 _Day;
00039 int16 _Year;
00041 int16 _Thousands;
00042
00044 int16 _Month;
00046 int16 _Seconds;
00048 int16 _Minutes;
00050 int16 _Hours;
00051
00053 int16 _Tz;
00054
00056 uchar _Format;
00058 static uchar DefaultFormat;
00060 static char DefaultSeparator;
00061
00062 public:
00063 GDateTime();
00064 ~GDateTime();
00065
00066 enum
00067 {
00070 #ifdef WIN32
00071 Second64Bit = 10000000,
00072 #else
00073 Second64Bit = 1000,
00074 #endif
00075 };
00076
00078 int Day() { return _Day; }
00080 void Day(int d) { _Day = d; }
00082 int Month() { return _Month; }
00084 void Month(int m) { _Month = m; }
00086 void Month(char *m);
00088 int Year() { return _Year; }
00090 void Year(int y) { _Year = y; }
00091
00093 int Thousands() { return _Thousands; }
00095 void Thousands(int t) { _Thousands = t; }
00097 int Seconds() { return _Seconds; }
00099 void Seconds(int s) { _Seconds = s; }
00101 int Minutes() { return _Minutes; }
00103 void Minutes(int m) { _Minutes = m; }
00105 int Hours() { return _Hours; }
00107 void Hours(int h) { _Hours = h; }
00108
00110 int GetTimeZone() { return _Tz; }
00112 void SetTimeZone
00113 (
00115 int Tz,
00118 bool ConvertTime
00119 );
00122 void ToUtc() { SetTimeZone(0, true); }
00125 void ToLocal() { SetTimeZone(SystemTimeZone(), true); }
00126
00130 uchar GetFormat() { return _Format; }
00133 void SetFormat
00134 (
00136 uchar f
00137 ) { _Format = f; }
00139 static uchar GetDefaultFormat();
00141 static void SetDefaultFormat(uchar f) { DefaultFormat = f; }
00142
00144 int DayOfWeek();
00145
00148 void Get(char *Str);
00150 bool Get(uint64 &s);
00153 void GetDate(char *Str);
00156 void GetTime(char *Str);
00157
00159 void SetNow();
00162 bool Set(char *Str);
00164 bool Set(uint64 s);
00166 bool Set(time_t tt);
00169 bool SetDate(char *Str);
00172 bool SetTime(char *Str);
00173
00175 bool IsLeapYear
00176 (
00178 int Year = -1
00179 );
00181 bool IsSameDay(GDateTime &d);
00183 int DaysInMonth();
00184
00186 void AddSeconds(int64 Seconds);
00188 void AddMinutes(int Minutes);
00190 void AddHours(int Hours);
00192 void AddDays(int Days);
00194 void AddMonths(int Months);
00195
00197 static int SystemTimeZone(bool ForceUpdate = false);
00200 static int SystemTimeZoneOffset();
00201
00203 struct LgiClass GDstInfo
00204 {
00206 int64 UtcTimeStamp;
00208 int Offset;
00209
00210 GDateTime GetLocal();
00211 };
00212
00216 static bool
00217 GetDaylightSavingsInfo
00218 (
00221 GArray<GDstInfo> &Out,
00223 GDateTime &Start,
00225 GDateTime *End = 0
00226 );
00227
00228
00229 int Sizeof();
00230 bool Serialize(class GFile &f, bool Write);
00231 bool Serialize(class GDom *Props, char *Name, bool Write);
00232
00233
00234 bool operator <(GDateTime &dt);
00235 bool operator <=(GDateTime &dt);
00236 bool operator >(GDateTime &dt);
00237 bool operator >=(GDateTime &dt);
00238 bool operator ==(GDateTime &dt);
00239 bool operator !=(GDateTime &dt);
00240 int Compare(GDateTime *d);
00241
00242 GDateTime operator -(GDateTime &dt);
00243 GDateTime operator +(GDateTime &dt);
00244 GDateTime DiffMonths(GDateTime &dt);
00245
00246 operator uint64()
00247 {
00248 uint64 ts = 0;
00249 Get(ts);
00250 return ts;
00251 }
00252
00253 GDateTime &operator =(uint64 ts)
00254 {
00255 Set(ts);
00256 return *this;
00257 }
00258 };
00259
00261 struct GTimeZone
00262 {
00263 public:
00265 float Offset;
00267 char *Text;
00268 };
00269
00271 extern GTimeZone GTimeZones[];
00272
00273 #endif