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 "SkString.h" | 8 #include "SkString.h" |
9 #include "SkTime.h" | 9 #include "SkTime.h" |
10 | 10 |
11 void SkTime::DateTime::toISO8601(SkString* dst) const { | 11 void SkTime::DateTime::toISO8601(SkString* dst) const { |
12 if (dst) { | 12 if (dst) { |
13 int timeZoneMinutes = SkToInt(fTimeZoneMinutes); | 13 int timeZoneMinutes = SkToInt(fTimeZoneMinutes); |
14 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; | 14 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; |
15 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; | 15 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; |
16 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; | 16 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; |
17 dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d", | 17 dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d", |
18 static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth), | 18 static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth), |
19 static_cast<unsigned>(fDay), static_cast<unsigned>(fHour), | 19 static_cast<unsigned>(fDay), static_cast<unsigned>(fHour), |
20 static_cast<unsigned>(fMinute), | 20 static_cast<unsigned>(fMinute), |
21 static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours, | 21 static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours, |
22 timeZoneMinutes); | 22 timeZoneMinutes); |
23 } | 23 } |
24 } | 24 } |
25 | |
26 // TODO: use std::chrono on Mach too, when available. | |
27 | |
28 #if defined(__MACH__) | |
29 #include "SkOncePtr.h" | |
30 #include <mach/mach_time.h> | |
31 SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick); | |
32 double SkTime::GetNSecs() { | |
33 uint64_t ticks = mach_absolute_time(); | |
34 return ticks * *ns_per_tick.get([]{ | |
35 mach_timebase_info_data_t timebase; | |
36 (void)mach_timebase_info(&timebase); | |
37 return new double(timebase.numer * 1.0 / timebase.denom); | |
38 }); | |
39 } | |
40 #else | |
41 #include <chrono> | |
42 double SkTime::GetNSecs() { | |
43 auto now = std::chrono::high_resolution_clock::now(); | |
44 std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); | |
45 return ns.count(); | |
46 } | |
47 #endif | |
OLD | NEW |