11 #if defined(_MSC_VER) || defined(_MSC_EXTEIO)
12 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
14 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
17 static int gettimeofday(struct timeval *tv, struct timezone *tz)
20 unsigned __int64 tmpres = 0;
25 GetSystemTimeAsFileTime(&ft);
27 tmpres = ft.dwHighDateTime;
29 tmpres |= ft.dwLowDateTime;
31 /*converting file time to unix epoch*/
32 tmpres /= 10; /*convert into microseconds*/
33 tmpres -= DELTA_EPOCH_IN_MICROSECS;
34 tv->tv_sec = (long)(tmpres / 1000000UL);
35 tv->tv_usec = (long)(tmpres % 1000000UL);
46 tz->tz_minuteswest = _get_timezone / 60;
47 tz->tz_dsttime = _daylight;
61 DebugLog2("Date::Date()");
65 _zone.tz_minuteswest = 0;
73 _zone.tz_minuteswest = 0;
76 DebugLog2("Date::~Date()");
81 DebugLog2("Date::alloc()");
88 DebugLog2("Date::date()");
91 result = Date::alloc()->init();
94 result->autorelease();
99 Date *Date::dateWithTimeIntervalSinceNow(TimeInterval seconds)
101 DebugLog2("Date::dateWithTimeIntervalSinceNow(seconds)");
104 result = Date::alloc()->initWithTimeIntervalSinceNow(seconds);
107 result->autorelease();
114 DebugLog2("Date::init()");
116 if (gettimeofday(&_time, &_zone) != 0)
123 Date *Date::initWithTimeInterval(TimeInterval seconds, Date *refDate)
125 DebugLog2("Date::initWithTimeInterval(seconds,refDate)");
132 _time = refDate->_time;
133 _zone = refDate->_zone;
135 _time.tv_sec += (int)seconds;
136 _time.tv_usec += ((int)(seconds * 1000000)) % 1000000;
137 if (_time.tv_usec >= 1000000)
140 _time.tv_usec -= 1000000;
146 Date *Date::initWithTimeIntervalSinceNow(TimeInterval seconds)
148 DebugLog2("Date::initWithTimeIntervalSinceNow(seconds)");
150 if (gettimeofday(&_time, &_zone) != 0)
155 _time.tv_sec += (int)seconds;
156 _time.tv_usec += ((int)(seconds * 1000000)) % 1000000;
157 if (_time.tv_usec >= 1000000)
160 _time.tv_usec -= 1000000;
166 TimeInterval Date::timeIntervalSinceDate(Date *anotherDate)
168 DebugLog2("Date::timeIntervalSinceDate(anotherDate)");
170 if (anotherDate == NULL)
175 TimeInterval self, another;
176 self = _time.tv_usec;
177 self = _time.tv_sec + self / 1000000;
178 another = anotherDate->_time.tv_usec;
179 another = anotherDate->_time.tv_sec + another / 1000000;
181 return self - another;
184 Date *Date::dateByAddingTimeInterval(TimeInterval seconds)
186 DebugLog2("Date::dateByAddingTimeInterval(seconds)");
188 Date *result = Date::alloc()->initWithTimeInterval(seconds, this);
191 result->autorelease();
196 ComparisonResult Date::compare(Date *anotherDate)
198 DebugLog2("Date::compare(anotherDate)");
204 if ((_time.tv_sec < anotherDate->_time.tv_sec) ||
205 ((_time.tv_sec == anotherDate->_time.tv_sec) && (_time.tv_usec < anotherDate->_time.tv_usec)))
207 return OrderedAscending;
209 if ((_time.tv_sec == anotherDate->_time.tv_sec) && (_time.tv_usec == anotherDate->_time.tv_usec))
213 return OrderedDescending;
216 const char *Date::className()