| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |  | 
| 2 // Use of this source code is governed by a BSD-style license that can be |  | 
| 3 // found in the LICENSE file. |  | 
| 4 // |  | 
| 5 // Windows specific time functions. |  | 
| 6 |  | 
| 7 #include <time.h> |  | 
| 8 #include <windows.h> |  | 
| 9 |  | 
| 10 #include "chrome/browser/sync/notifier/base/time.h" |  | 
| 11 |  | 
| 12 #include "chrome/browser/sync/notifier/base/utils.h" |  | 
| 13 #include "talk/base/common.h" |  | 
| 14 #include "talk/base/logging.h" |  | 
| 15 |  | 
| 16 namespace notifier { |  | 
| 17 |  | 
| 18 time64 FileTimeToTime64(const FILETIME& file_time) { |  | 
| 19   return static_cast<time64>(file_time.dwHighDateTime) << 32 | |  | 
| 20       file_time.dwLowDateTime; |  | 
| 21 } |  | 
| 22 |  | 
| 23 void Time64ToFileTime(const time64& time, FILETIME* ft) { |  | 
| 24   ASSERT(ft); |  | 
| 25 |  | 
| 26   ft->dwHighDateTime = static_cast<DWORD>(time >> 32); |  | 
| 27   ft->dwLowDateTime = static_cast<DWORD>(time & 0xffffffff); |  | 
| 28 } |  | 
| 29 |  | 
| 30 void TmTimeToSystemTime(const struct tm& tm, SYSTEMTIME* sys_time) { |  | 
| 31   ASSERT(sys_time); |  | 
| 32 |  | 
| 33   SetZero(*sys_time); |  | 
| 34   // tm's year is 1900 based, systemtime's year is absolute. |  | 
| 35   sys_time->wYear = tm.tm_year + 1900; |  | 
| 36   // tm's month is 0 based, but systemtime's month is 1 based. |  | 
| 37   sys_time->wMonth = tm.tm_mon + 1; |  | 
| 38   sys_time->wDay = tm.tm_mday; |  | 
| 39   sys_time->wDayOfWeek = tm.tm_wday; |  | 
| 40   sys_time->wHour = tm.tm_hour; |  | 
| 41   sys_time->wMinute = tm.tm_min; |  | 
| 42   sys_time->wSecond = tm.tm_sec; |  | 
| 43 } |  | 
| 44 |  | 
| 45 void SystemTimeToTmTime(const SYSTEMTIME& sys_time, struct tm* tm) { |  | 
| 46   ASSERT(tm); |  | 
| 47 |  | 
| 48   SetZero(*tm); |  | 
| 49   // tm's year is 1900 based, systemtime's year is absolute. |  | 
| 50   tm->tm_year = sys_time.wYear - 1900; |  | 
| 51   // tm's month is 0 based, but systemtime's month is 1 based. |  | 
| 52   tm->tm_mon = sys_time.wMonth - 1; |  | 
| 53   tm->tm_mday = sys_time.wDay; |  | 
| 54   tm->tm_wday = sys_time.wDayOfWeek; |  | 
| 55   tm->tm_hour = sys_time.wHour; |  | 
| 56   tm->tm_min = sys_time.wMinute; |  | 
| 57   tm->tm_sec = sys_time.wSecond; |  | 
| 58 } |  | 
| 59 |  | 
| 60 time64 GetCurrent100NSTime() { |  | 
| 61   // In order to get the 100ns time we shouldn't use SystemTime as it's |  | 
| 62   // granularity is 1 ms. Below is the correct implementation. On the other |  | 
| 63   // hand the system clock granularity is 15 ms, so we are not gaining much by |  | 
| 64   // having the timestamp in nano-sec. If we decide to go with ms, divide |  | 
| 65   // "time64 time" by 10000. |  | 
| 66   FILETIME file_time; |  | 
| 67   ::GetSystemTimeAsFileTime(&file_time); |  | 
| 68 |  | 
| 69   time64 time = FileTimeToTime64(file_time); |  | 
| 70   return time; |  | 
| 71 } |  | 
| 72 |  | 
| 73 time64 TmToTime64(const struct tm& tm) { |  | 
| 74   SYSTEMTIME sys_time; |  | 
| 75   TmTimeToSystemTime(tm, &sys_time); |  | 
| 76 |  | 
| 77   FILETIME file_time; |  | 
| 78   SetZero(file_time); |  | 
| 79   if (!::SystemTimeToFileTime(&sys_time, &file_time)) { |  | 
| 80     return 0; |  | 
| 81   } |  | 
| 82 |  | 
| 83   return FileTimeToTime64(file_time); |  | 
| 84 } |  | 
| 85 |  | 
| 86 bool Time64ToTm(time64 t, struct tm* tm) { |  | 
| 87   ASSERT(tm); |  | 
| 88 |  | 
| 89   FILETIME file_time; |  | 
| 90   SetZero(file_time); |  | 
| 91   Time64ToFileTime(t, &file_time); |  | 
| 92 |  | 
| 93   SYSTEMTIME sys_time; |  | 
| 94   SetZero(sys_time); |  | 
| 95   if (!::FileTimeToSystemTime(&file_time, &sys_time)) { |  | 
| 96     return false; |  | 
| 97   } |  | 
| 98 |  | 
| 99   SystemTimeToTmTime(sys_time, tm); |  | 
| 100 |  | 
| 101   return true; |  | 
| 102 } |  | 
| 103 |  | 
| 104 }  // namespace notifier |  | 
| OLD | NEW | 
|---|