| 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 "SkLeanWindows.h" |
| 8 #include "SkString.h" | 9 #include "SkString.h" |
| 9 #include "SkTime.h" | 10 #include "SkTime.h" |
| 10 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 11 #include <chrono> | 12 #include <chrono> |
| 12 | 13 |
| 13 void SkTime::DateTime::toISO8601(SkString* dst) const { | 14 void SkTime::DateTime::toISO8601(SkString* dst) const { |
| 14 if (dst) { | 15 if (dst) { |
| 15 int timeZoneMinutes = SkToInt(fTimeZoneMinutes); | 16 int timeZoneMinutes = SkToInt(fTimeZoneMinutes); |
| 16 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; | 17 char timezoneSign = timeZoneMinutes >= 0 ? '+' : '-'; |
| 17 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; | 18 int timeZoneHours = SkTAbs(timeZoneMinutes) / 60; |
| 18 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; | 19 timeZoneMinutes = SkTAbs(timeZoneMinutes) % 60; |
| 19 dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d", | 20 dst->printf("%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02d", |
| 20 static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth), | 21 static_cast<unsigned>(fYear), static_cast<unsigned>(fMonth), |
| 21 static_cast<unsigned>(fDay), static_cast<unsigned>(fHour), | 22 static_cast<unsigned>(fDay), static_cast<unsigned>(fHour), |
| 22 static_cast<unsigned>(fMinute), | 23 static_cast<unsigned>(fMinute), |
| 23 static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours, | 24 static_cast<unsigned>(fSecond), timezoneSign, timeZoneHours, |
| 24 timeZoneMinutes); | 25 timeZoneMinutes); |
| 25 } | 26 } |
| 26 } | 27 } |
| 27 | 28 |
| 28 | |
| 29 #ifdef SK_BUILD_FOR_WIN32 | 29 #ifdef SK_BUILD_FOR_WIN32 |
| 30 | 30 |
| 31 #include "windows.h" | |
| 32 void SkTime::GetDateTime(DateTime* dt) { | 31 void SkTime::GetDateTime(DateTime* dt) { |
| 33 if (dt) { | 32 if (dt) { |
| 34 SYSTEMTIME st; | 33 SYSTEMTIME st; |
| 35 GetSystemTime(&st); | 34 GetSystemTime(&st); |
| 36 dt->fTimeZoneMinutes = 0; | 35 dt->fTimeZoneMinutes = 0; |
| 37 dt->fYear = st.wYear; | 36 dt->fYear = st.wYear; |
| 38 dt->fMonth = SkToU8(st.wMonth); | 37 dt->fMonth = SkToU8(st.wMonth); |
| 39 dt->fDayOfWeek = SkToU8(st.wDayOfWeek); | 38 dt->fDayOfWeek = SkToU8(st.wDayOfWeek); |
| 40 dt->fDay = SkToU8(st.wDay); | 39 dt->fDay = SkToU8(st.wDay); |
| 41 dt->fHour = SkToU8(st.wHour); | 40 dt->fHour = SkToU8(st.wHour); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 63 dt->fSecond = SkToU8(tstruct->tm_sec); | 62 dt->fSecond = SkToU8(tstruct->tm_sec); |
| 64 } | 63 } |
| 65 } | 64 } |
| 66 #endif // SK_BUILD_FOR_WIN32 | 65 #endif // SK_BUILD_FOR_WIN32 |
| 67 | 66 |
| 68 double SkTime::GetNSecs() { | 67 double SkTime::GetNSecs() { |
| 69 auto now = std::chrono::high_resolution_clock::now(); | 68 auto now = std::chrono::high_resolution_clock::now(); |
| 70 std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); | 69 std::chrono::duration<double, std::nano> ns = now.time_since_epoch(); |
| 71 return ns.count(); | 70 return ns.count(); |
| 72 } | 71 } |
| OLD | NEW |