summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/JavaScriptCore/runtime/DateMath.cpp
diff options
context:
space:
mode:
authorTobias Koenig <tokoe@kde.org>2009-06-16 16:07:42 (GMT)
committerTobias Koenig <tokoe@kde.org>2009-06-16 16:07:42 (GMT)
commit65c2d095cddfda32052925654dd1defd314ad4b3 (patch)
tree222ac5b04cd1c7a273b0c22d01d0ff3682d5d2d3 /src/3rdparty/webkit/JavaScriptCore/runtime/DateMath.cpp
parentf1e6e89f7ee452af0e4404af537f5fed2a2b2dc5 (diff)
parentd9308550f104526d29b1cdd56514ae3bb967d7f9 (diff)
downloadQt-65c2d095cddfda32052925654dd1defd314ad4b3.zip
Qt-65c2d095cddfda32052925654dd1defd314ad4b3.tar.gz
Qt-65c2d095cddfda32052925654dd1defd314ad4b3.tar.bz2
Merge branch 'master' of git://gitorious.org/qt/qt
Diffstat (limited to 'src/3rdparty/webkit/JavaScriptCore/runtime/DateMath.cpp')
-rw-r--r--src/3rdparty/webkit/JavaScriptCore/runtime/DateMath.cpp146
1 files changed, 7 insertions, 139 deletions
diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/DateMath.cpp b/src/3rdparty/webkit/JavaScriptCore/runtime/DateMath.cpp
index 9cfe256..2f8c88c 100644
--- a/src/3rdparty/webkit/JavaScriptCore/runtime/DateMath.cpp
+++ b/src/3rdparty/webkit/JavaScriptCore/runtime/DateMath.cpp
@@ -48,6 +48,7 @@
#include <time.h>
#include <wtf/ASCIICType.h>
#include <wtf/Assertions.h>
+#include <wtf/CurrentTime.h>
#include <wtf/MathExtras.h>
#include <wtf/StringExtras.h>
@@ -67,10 +68,6 @@
#include <sys/timeb.h>
#endif
-#if HAVE(STRINGS_H)
-#include <strings.h>
-#endif
-
using namespace WTF;
namespace JSC {
@@ -291,139 +288,10 @@ double getCurrentUTCTime()
return floor(getCurrentUTCTimeWithMicroseconds());
}
-#if PLATFORM(WIN_OS)
-
-static LARGE_INTEGER qpcFrequency;
-static bool syncedTime;
-
-static double highResUpTime()
-{
- // We use QPC, but only after sanity checking its result, due to bugs:
- // http://support.microsoft.com/kb/274323
- // http://support.microsoft.com/kb/895980
- // http://msdn.microsoft.com/en-us/library/ms644904.aspx ("...you can get different results on different processors due to bugs in the basic input/output system (BIOS) or the hardware abstraction layer (HAL)."
-
- static LARGE_INTEGER qpcLast;
- static DWORD tickCountLast;
- static bool inited;
-
- LARGE_INTEGER qpc;
- QueryPerformanceCounter(&qpc);
- DWORD tickCount = GetTickCount();
-
- if (inited) {
- __int64 qpcElapsed = ((qpc.QuadPart - qpcLast.QuadPart) * 1000) / qpcFrequency.QuadPart;
- __int64 tickCountElapsed;
- if (tickCount >= tickCountLast)
- tickCountElapsed = (tickCount - tickCountLast);
- else {
-#if COMPILER(MINGW)
- __int64 tickCountLarge = tickCount + 0x100000000ULL;
-#else
- __int64 tickCountLarge = tickCount + 0x100000000I64;
-#endif
- tickCountElapsed = tickCountLarge - tickCountLast;
- }
-
- // force a re-sync if QueryPerformanceCounter differs from GetTickCount by more than 500ms.
- // (500ms value is from http://support.microsoft.com/kb/274323)
- __int64 diff = tickCountElapsed - qpcElapsed;
- if (diff > 500 || diff < -500)
- syncedTime = false;
- } else
- inited = true;
-
- qpcLast = qpc;
- tickCountLast = tickCount;
-
- return (1000.0 * qpc.QuadPart) / static_cast<double>(qpcFrequency.QuadPart);;
-}
-
-static double lowResUTCTime()
-{
-#if PLATFORM(WIN_CE)
- SYSTEMTIME systemTime;
- GetSystemTime(&systemTime);
- struct tm tmtime;
- tmtime.tm_year = systemTime.wYear - 1900;
- tmtime.tm_mon = systemTime.wMonth - 1;
- tmtime.tm_mday = systemTime.wDay;
- tmtime.tm_wday = systemTime.wDayOfWeek;
- tmtime.tm_hour = systemTime.wHour;
- tmtime.tm_min = systemTime.wMinute;
- tmtime.tm_sec = systemTime.wSecond;
- time_t timet = mktime(&tmtime);
- return timet * msPerSecond + systemTime.wMilliseconds;
-#else
- struct _timeb timebuffer;
- _ftime(&timebuffer);
- return timebuffer.time * msPerSecond + timebuffer.millitm;
-#endif
-}
-
-static bool qpcAvailable()
-{
- static bool available;
- static bool checked;
-
- if (checked)
- return available;
-
- available = QueryPerformanceFrequency(&qpcFrequency);
- checked = true;
- return available;
-}
-
-#endif
-
+// Returns current time in milliseconds since 1 Jan 1970.
double getCurrentUTCTimeWithMicroseconds()
{
-#if PLATFORM(WIN_OS)
- // Use a combination of ftime and QueryPerformanceCounter.
- // ftime returns the information we want, but doesn't have sufficient resolution.
- // QueryPerformanceCounter has high resolution, but is only usable to measure time intervals.
- // To combine them, we call ftime and QueryPerformanceCounter initially. Later calls will use QueryPerformanceCounter
- // by itself, adding the delta to the saved ftime. We periodically re-sync to correct for drift.
- static bool started;
- static double syncLowResUTCTime;
- static double syncHighResUpTime;
- static double lastUTCTime;
-
- double lowResTime = lowResUTCTime();
-
- if (!qpcAvailable())
- return lowResTime;
-
- double highResTime = highResUpTime();
-
- if (!syncedTime) {
- timeBeginPeriod(1); // increase time resolution around low-res time getter
- syncLowResUTCTime = lowResTime = lowResUTCTime();
- timeEndPeriod(1); // restore time resolution
- syncHighResUpTime = highResTime;
- syncedTime = true;
- }
-
- double highResElapsed = highResTime - syncHighResUpTime;
- double utc = syncLowResUTCTime + highResElapsed;
-
- // force a clock re-sync if we've drifted
- double lowResElapsed = lowResTime - syncLowResUTCTime;
- const double maximumAllowedDriftMsec = 15.625 * 2.0; // 2x the typical low-res accuracy
- if (fabs(highResElapsed - lowResElapsed) > maximumAllowedDriftMsec)
- syncedTime = false;
-
- // make sure time doesn't run backwards (only correct if difference is < 2 seconds, since DST or clock changes could occur)
- const double backwardTimeLimit = 2000.0;
- if (utc < lastUTCTime && (lastUTCTime - utc) < backwardTimeLimit)
- return lastUTCTime;
- lastUTCTime = utc;
-#else
- struct timeval tv;
- gettimeofday(&tv, 0);
- double utc = tv.tv_sec * msPerSecond + tv.tv_usec / 1000.0;
-#endif
- return utc;
+ return currentTime() * 1000.0;
}
void getLocalTime(const time_t* localTime, struct tm* localTM)
@@ -1047,14 +915,14 @@ UString formatTime(const GregorianDateTime &t, bool utc)
snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", t.hour, t.minute, t.second);
} else {
int offset = abs(gmtoffset(t));
- char tzname[70];
+ char timeZoneName[70];
struct tm gtm = t;
- strftime(tzname, sizeof(tzname), "%Z", &gtm);
+ strftime(timeZoneName, sizeof(timeZoneName), "%Z", &gtm);
- if (tzname[0]) {
+ if (timeZoneName[0]) {
snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d (%s)",
t.hour, t.minute, t.second,
- gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, tzname);
+ gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, timeZoneName);
} else {
snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d",
t.hour, t.minute, t.second,