michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "SkTime.h" michael@0: michael@0: #ifdef SK_BUILD_FOR_WIN michael@0: michael@0: #ifdef SK_DEBUG michael@0: SkMSec gForceTickCount = (SkMSec) -1; michael@0: #endif michael@0: michael@0: void SkTime::GetDateTime(DateTime* t) { michael@0: if (t) { michael@0: SYSTEMTIME syst; michael@0: michael@0: ::GetLocalTime(&syst); michael@0: t->fYear = SkToU16(syst.wYear); michael@0: t->fMonth = SkToU8(syst.wMonth); michael@0: t->fDayOfWeek = SkToU8(syst.wDayOfWeek); michael@0: t->fDay = SkToU8(syst.wDay); michael@0: t->fHour = SkToU8(syst.wHour); michael@0: t->fMinute = SkToU8(syst.wMinute); michael@0: t->fSecond = SkToU8(syst.wSecond); michael@0: } michael@0: } michael@0: michael@0: SkMSec SkTime::GetMSecs() { michael@0: #ifdef SK_DEBUG michael@0: if (gForceTickCount != (SkMSec) -1) { michael@0: return gForceTickCount; michael@0: } michael@0: #endif michael@0: return ::GetTickCount(); michael@0: } michael@0: michael@0: #elif defined(xSK_BUILD_FOR_MAC) michael@0: michael@0: #include michael@0: michael@0: void SkTime::GetDateTime(DateTime* t) { michael@0: if (t) { michael@0: tm syst; michael@0: time_t tm; michael@0: michael@0: time(&tm); michael@0: localtime_r(&tm, &syst); michael@0: t->fYear = SkToU16(syst.tm_year); michael@0: t->fMonth = SkToU8(syst.tm_mon + 1); michael@0: t->fDayOfWeek = SkToU8(syst.tm_wday); michael@0: t->fDay = SkToU8(syst.tm_mday); michael@0: t->fHour = SkToU8(syst.tm_hour); michael@0: t->fMinute = SkToU8(syst.tm_min); michael@0: t->fSecond = SkToU8(syst.tm_sec); michael@0: } michael@0: } michael@0: michael@0: SkMSec SkTime::GetMSecs() { michael@0: UnsignedWide wide; michael@0: ::Microseconds(&wide); michael@0: michael@0: int64_t s = ((int64_t)wide.hi << 32) | wide.lo; michael@0: s = (s + 500) / 1000; // rounded divide michael@0: return (SkMSec)s; michael@0: } michael@0: michael@0: #endif