1 2 /* 3 * Copyright 2006 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #include "SkTime.h" 11 12 #ifdef SK_BUILD_FOR_WIN 13 14 #ifdef SK_DEBUG 15 SkMSec gForceTickCount = (SkMSec) -1; 16 #endif 17 GetDateTime(DateTime * t)18void SkTime::GetDateTime(DateTime* t) 19 { 20 if (t) 21 { 22 SYSTEMTIME syst; 23 24 ::GetLocalTime(&syst); 25 t->fYear = SkToU16(syst.wYear); 26 t->fMonth = SkToU8(syst.wMonth); 27 t->fDayOfWeek = SkToU8(syst.wDayOfWeek); 28 t->fDay = SkToU8(syst.wDay); 29 t->fHour = SkToU8(syst.wHour); 30 t->fMinute = SkToU8(syst.wMinute); 31 t->fSecond = SkToU8(syst.wSecond); 32 } 33 } 34 GetMSecs()35SkMSec SkTime::GetMSecs() 36 { 37 #ifdef SK_DEBUG 38 if (gForceTickCount != (SkMSec) -1) 39 return gForceTickCount; 40 #endif 41 return ::GetTickCount(); 42 } 43 44 #elif defined(xSK_BUILD_FOR_MAC) 45 46 #include <time.h> 47 GetDateTime(DateTime * t)48void SkTime::GetDateTime(DateTime* t) 49 { 50 if (t) 51 { 52 tm syst; 53 time_t tm; 54 55 time(&tm); 56 localtime_r(&tm, &syst); 57 t->fYear = SkToU16(syst.tm_year); 58 t->fMonth = SkToU8(syst.tm_mon + 1); 59 t->fDayOfWeek = SkToU8(syst.tm_wday); 60 t->fDay = SkToU8(syst.tm_mday); 61 t->fHour = SkToU8(syst.tm_hour); 62 t->fMinute = SkToU8(syst.tm_min); 63 t->fSecond = SkToU8(syst.tm_sec); 64 } 65 } 66 67 #include "Sk64.h" 68 GetMSecs()69SkMSec SkTime::GetMSecs() 70 { 71 UnsignedWide wide; 72 Sk64 s; 73 74 ::Microseconds(&wide); 75 s.set(wide.hi, wide.lo); 76 s.div(1000, Sk64::kRound_DivOption); 77 return s.get32(); 78 } 79 80 #endif 81 82