blob: a4e035bd1e2ed53199d8a50b317990252208ac73 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#include "SkTime.h"
9
10#ifdef SK_BUILD_FOR_WIN
11
12#ifdef SK_DEBUG
13SkMSec gForceTickCount = (SkMSec) -1;
14#endif
15
reed@google.combf0001d2014-01-13 14:53:55 +000016void SkTime::GetDateTime(DateTime* t) {
17 if (t) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000018 SYSTEMTIME syst;
19
20 ::GetLocalTime(&syst);
21 t->fYear = SkToU16(syst.wYear);
22 t->fMonth = SkToU8(syst.wMonth);
23 t->fDayOfWeek = SkToU8(syst.wDayOfWeek);
24 t->fDay = SkToU8(syst.wDay);
25 t->fHour = SkToU8(syst.wHour);
26 t->fMinute = SkToU8(syst.wMinute);
27 t->fSecond = SkToU8(syst.wSecond);
28 }
29}
30
reed@google.combf0001d2014-01-13 14:53:55 +000031SkMSec SkTime::GetMSecs() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000032#ifdef SK_DEBUG
reed@google.combf0001d2014-01-13 14:53:55 +000033 if (gForceTickCount != (SkMSec) -1) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 return gForceTickCount;
reed@google.combf0001d2014-01-13 14:53:55 +000035 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000036#endif
37 return ::GetTickCount();
38}
39
40#elif defined(xSK_BUILD_FOR_MAC)
41
42#include <time.h>
43
reed@google.combf0001d2014-01-13 14:53:55 +000044void SkTime::GetDateTime(DateTime* t) {
45 if (t) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 tm syst;
47 time_t tm;
rmistry@google.comd6176b02012-08-23 18:14:13 +000048
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 time(&tm);
50 localtime_r(&tm, &syst);
51 t->fYear = SkToU16(syst.tm_year);
52 t->fMonth = SkToU8(syst.tm_mon + 1);
53 t->fDayOfWeek = SkToU8(syst.tm_wday);
54 t->fDay = SkToU8(syst.tm_mday);
55 t->fHour = SkToU8(syst.tm_hour);
56 t->fMinute = SkToU8(syst.tm_min);
57 t->fSecond = SkToU8(syst.tm_sec);
58 }
59}
60
reed@google.combf0001d2014-01-13 14:53:55 +000061SkMSec SkTime::GetMSecs() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 UnsignedWide wide;
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 ::Microseconds(&wide);
reed@google.combf0001d2014-01-13 14:53:55 +000064
65 int64_t s = ((int64_t)wide.hi << 32) | wide.lo;
66 s = (s + 500) / 1000; // rounded divide
67 return (SkMSec)s;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068}
69
70#endif