Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: src/core/SkTime.cpp

Issue 1562943002: SkTime: Stop using POSIX entensions to time.h for timezone (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-01-11 (Monday) 17:28:49 EST Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/animator/SkTime.cpp ('k') | src/ports/SkTime_Unix.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « src/animator/SkTime.cpp ('k') | src/ports/SkTime_Unix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698