OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkOncePtr.h" | 8 #include "SkOncePtr.h" |
9 #include "SkString.h" | 9 #include "SkString.h" |
10 #include "SkTime.h" | 10 #include "SkTime.h" |
| 11 #include "SkTypes.h" |
11 | 12 |
12 void SkTime::DateTime::toISO8601(SkString* dst) const { | 13 void SkTime::DateTime::toISO8601(SkString* dst) const { |
13 if (dst) { | 14 if (dst) { |
14 int timeZoneMinutes = SkToInt(fTimeZoneMinutes); | 15 int timeZoneMinutes = SkToInt(fTimeZoneMinutes); |
15 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; | 16 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; |
16 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; | 17 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; |
17 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; | 18 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; |
18 dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d", | 19 dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d", |
19 static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth), | 20 static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth), |
20 static_cast<unsigned>(fDay), static_cast<unsigned>(fHour), | 21 static_cast<unsigned>(fDay), static_cast<unsigned>(fHour), |
21 static_cast<unsigned>(fMinute), | 22 static_cast<unsigned>(fMinute), |
22 static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours, | 23 static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours, |
23 timeZoneMinutes); | 24 timeZoneMinutes); |
24 } | 25 } |
25 } | 26 } |
26 | 27 |
| 28 |
| 29 #ifdef SK_BUILD_FOR_WIN32 |
| 30 |
| 31 #include "Windows.h" |
| 32 void SkTime::GetDateTime(DateTime* dt) { |
| 33 if (dt) { |
| 34 SYSTEMTIME st; |
| 35 GetSystemTime(&st); |
| 36 dt->fTimeZoneMinutes = 0; |
| 37 dt->fYear = st.wYear; |
| 38 dt->fMonth = SkToU8(st.wMonth); |
| 39 dt->fDayOfWeek = SkToU8(st.wDayOfWeek); |
| 40 dt->fDay = SkToU8(st.wDay); |
| 41 dt->fHour = SkToU8(st.wHour); |
| 42 dt->fMinute = SkToU8(st.wMinute); |
| 43 dt->fSecond = SkToU8(st.wSecond); |
| 44 } |
| 45 } |
| 46 |
| 47 #else // SK_BUILD_FOR_WIN32 |
| 48 |
| 49 #include <time.h> |
| 50 void SkTime::GetDateTime(DateTime* dt) { |
| 51 if (dt) { |
| 52 time_t m_time; |
| 53 time(&m_time); |
| 54 struct tm* tstruct; |
| 55 tstruct = gmtime(&m_time); |
| 56 dt->fTimeZoneMinutes = 0; |
| 57 dt->fYear = tstruct->tm_year + 1900; |
| 58 dt->fMonth = SkToU8(tstruct->tm_mon + 1); |
| 59 dt->fDayOfWeek = SkToU8(tstruct->tm_wday); |
| 60 dt->fDay = SkToU8(tstruct->tm_mday); |
| 61 dt->fHour = SkToU8(tstruct->tm_hour); |
| 62 dt->fMinute = SkToU8(tstruct->tm_min); |
| 63 dt->fSecond = SkToU8(tstruct->tm_sec); |
| 64 } |
| 65 } |
| 66 #endif // SK_BUILD_FOR_WIN32 |
| 67 |
27 #if defined(_MSC_VER) | 68 #if defined(_MSC_VER) |
28 // TODO: try std::chrono again with MSVC 2015? | 69 // TODO: try std::chrono again with MSVC 2015? |
29 #include <intrin.h> | 70 #include <intrin.h> |
30 SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick); | 71 SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick); |
31 double SkTime::GetNSecs() { | 72 double SkTime::GetNSecs() { |
32 uint64_t ticks = __rdtsc(); | 73 uint64_t ticks = __rdtsc(); |
33 return ticks * *ns_per_tick.get([]{ | 74 return ticks * *ns_per_tick.get([]{ |
34 LARGE_INTEGER khz; // The docs say this returns Hz, but it returns
KHz. | 75 LARGE_INTEGER khz; // The docs say this returns Hz, but it returns
KHz. |
35 QueryPerformanceFrequency(&khz); | 76 QueryPerformanceFrequency(&khz); |
36 return new double(1e6 / khz.QuadPart); | 77 return new double(1e6 / khz.QuadPart); |
(...skipping 14 matching lines...) Expand all Loading... |
51 #else | 92 #else |
52 // This std::chrono code looks great on Linux and Android, | 93 // This std::chrono code looks great on Linux and Android, |
53 // but MSVC 2013 returned mostly garbage (0ns times, etc). | 94 // but MSVC 2013 returned mostly garbage (0ns times, etc). |
54 #include <chrono> | 95 #include <chrono> |
55 double SkTime::GetNSecs() { | 96 double SkTime::GetNSecs() { |
56 auto now = std::chrono::high_resolution_clock::now(); | 97 auto now = std::chrono::high_resolution_clock::now(); |
57 std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); | 98 std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); |
58 return ns.count(); | 99 return ns.count(); |
59 } | 100 } |
60 #endif | 101 #endif |
OLD | NEW |