1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTime.h" 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_BUILD_FOR_WIN 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkMSec gForceTickCount = (SkMSec) -1; 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16bf0001d0472d727266762c5967ec0d919a6df083reed@google.comvoid SkTime::GetDateTime(DateTime* t) { 17bf0001d0472d727266762c5967ec0d919a6df083reed@google.com if (t) { 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SYSTEMTIME syst; 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ::GetLocalTime(&syst); 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fYear = SkToU16(syst.wYear); 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fMonth = SkToU8(syst.wMonth); 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fDayOfWeek = SkToU8(syst.wDayOfWeek); 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fDay = SkToU8(syst.wDay); 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fHour = SkToU8(syst.wHour); 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fMinute = SkToU8(syst.wMinute); 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fSecond = SkToU8(syst.wSecond); 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 31bf0001d0472d727266762c5967ec0d919a6df083reed@google.comSkMSec SkTime::GetMSecs() { 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 33bf0001d0472d727266762c5967ec0d919a6df083reed@google.com if (gForceTickCount != (SkMSec) -1) { 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return gForceTickCount; 35bf0001d0472d727266762c5967ec0d919a6df083reed@google.com } 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return ::GetTickCount(); 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#elif defined(xSK_BUILD_FOR_MAC) 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <time.h> 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 44bf0001d0472d727266762c5967ec0d919a6df083reed@google.comvoid SkTime::GetDateTime(DateTime* t) { 45bf0001d0472d727266762c5967ec0d919a6df083reed@google.com if (t) { 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tm syst; 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com time_t tm; 48d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com time(&tm); 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com localtime_r(&tm, &syst); 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fYear = SkToU16(syst.tm_year); 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fMonth = SkToU8(syst.tm_mon + 1); 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fDayOfWeek = SkToU8(syst.tm_wday); 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fDay = SkToU8(syst.tm_mday); 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fHour = SkToU8(syst.tm_hour); 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fMinute = SkToU8(syst.tm_min); 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com t->fSecond = SkToU8(syst.tm_sec); 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 61bf0001d0472d727266762c5967ec0d919a6df083reed@google.comSkMSec SkTime::GetMSecs() { 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com UnsignedWide wide; 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ::Microseconds(&wide); 64bf0001d0472d727266762c5967ec0d919a6df083reed@google.com 65bf0001d0472d727266762c5967ec0d919a6df083reed@google.com int64_t s = ((int64_t)wide.hi << 32) | wide.lo; 66bf0001d0472d727266762c5967ec0d919a6df083reed@google.com s = (s + 500) / 1000; // rounded divide 67bf0001d0472d727266762c5967ec0d919a6df083reed@google.com return (SkMSec)s; 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 71