| OLD | NEW |
| (Empty) |
| 1 // Copyright 2004-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 // | |
| 16 // Time functions | |
| 17 | |
| 18 #ifndef OMAHA_BASE_TIME_H_ | |
| 19 #define OMAHA_BASE_TIME_H_ | |
| 20 | |
| 21 #include <windows.h> | |
| 22 #include <atlstr.h> | |
| 23 #include "base/basictypes.h" | |
| 24 | |
| 25 namespace omaha { | |
| 26 | |
| 27 #define kMicrosecsTo100ns (10ULL) | |
| 28 #define kMillisecsTo100ns (10000ULL) | |
| 29 #define kSecsTo100ns (1000 * kMillisecsTo100ns) | |
| 30 #define kMinsTo100ns (60 * kSecsTo100ns) | |
| 31 #define kHoursTo100ns (60 * kMinsTo100ns) | |
| 32 #define kDaysTo100ns (24 * kHoursTo100ns) | |
| 33 | |
| 34 // Jan 1 1980 was tuesday (day 2) | |
| 35 #define kStartSystemTime {1980, 1, 2, 1, 0, 0, 0, 0} | |
| 36 | |
| 37 // this is Jan 1 1980 in time64 | |
| 38 #define kStart100NsTime (119600064000000000uI64) | |
| 39 #define kTimeGranularity (kDaysTo100ns) | |
| 40 | |
| 41 // 2^15-1 because we use signed delta times | |
| 42 #define kTime16Max ((1 << 15) - 1) | |
| 43 | |
| 44 // Constant value used in conversion between FILETIME and time_t | |
| 45 // It is the time difference between January 1, 1601 and January 1, 1970 | |
| 46 #define kTimeTConvValue (116444736000000000) | |
| 47 | |
| 48 typedef uint16 time16; | |
| 49 typedef uint64 time64; | |
| 50 | |
| 51 time64 ConvertTime16ToTime64(uint16 time16); | |
| 52 uint16 ConvertTime64ToTime16(time64 time); | |
| 53 | |
| 54 #ifdef _DEBUG | |
| 55 void ComputeStartTime(); | |
| 56 #endif | |
| 57 | |
| 58 uint64 GetCurrent100NSTime(); | |
| 59 | |
| 60 uint64 GetCurrentMsTime(); | |
| 61 | |
| 62 // Note - these return 0 if we can't convert the time | |
| 63 time64 SystemTimeToTime64(const SYSTEMTIME *sys_time); | |
| 64 | |
| 65 // Conversions to/from values compatible with | |
| 66 // EXE/DLL timestamps and the C time() function | |
| 67 // NOTE: behavior is independent of wMilliseconds value | |
| 68 int32 SystemTimeToInt32(const SYSTEMTIME *sys_time); | |
| 69 int32 Time64ToInt32(const time64 & time); | |
| 70 time64 Int32ToTime64(const int32 & time); | |
| 71 time64 TimeTToTime64(const time_t& old_value); | |
| 72 | |
| 73 // Returns the system time in GMT | |
| 74 SYSTEMTIME Time64ToSystemTime(const time64 & time); | |
| 75 | |
| 76 // Returns the system time in the computer's time zone | |
| 77 SYSTEMTIME Time64ToLocalTime(const time64 & time); | |
| 78 | |
| 79 // Returns the UTC (system) time given the local time | |
| 80 SYSTEMTIME LocalTimeToSystemTime(const SYSTEMTIME *local_time); | |
| 81 | |
| 82 // This returns a standard formatted string that represents | |
| 83 // the UTC time corresponding to 'ft'. This is suitable for use | |
| 84 // in e.g. HTTP headers. | |
| 85 // | |
| 86 // @note IMPORTANT! This does not return a localized string - it's | |
| 87 // always in English. The string returned is intended for use in | |
| 88 // machine-readable contexts, i.e. HTTP headers and thus should not | |
| 89 // be localized. | |
| 90 CString ConvertTimeToGMTString(const FILETIME *ft); | |
| 91 | |
| 92 // Convert to and from FileTime | |
| 93 time64 FileTimeToTime64(const FILETIME & file_time); | |
| 94 void Time64ToFileTime(const time64 & time, FILETIME *ft); | |
| 95 | |
| 96 void SetTimeOverride(const time64 & time_new); | |
| 97 | |
| 98 // Convert from FILETIME to time_t | |
| 99 time_t FileTimeToTimeT(const FILETIME& file_time); | |
| 100 | |
| 101 // Convert from time_t to FILETIME | |
| 102 void TimeTToFileTime(const time_t& time, FILETIME* file_time); | |
| 103 | |
| 104 // Parses RFC 822 Date/Time format | |
| 105 // 5. DATE AND TIME SPECIFICATION | |
| 106 // 5.1. SYNTAX | |
| 107 // | |
| 108 // date-time = [ day "," ] date time ; dd mm yy | |
| 109 // ; hh:mm:ss zzz | |
| 110 // day = "Mon" / "Tue" / "Wed" / "Thu" | |
| 111 // / "Fri" / "Sat" / "Sun" | |
| 112 // | |
| 113 // date = 1*2DIGIT month 2DIGIT ; day month year | |
| 114 // ; e.g. 20 Jun 82 | |
| 115 // | |
| 116 // month = "Jan" / "Feb" / "Mar" / "Apr" | |
| 117 // / "May" / "Jun" / "Jul" / "Aug" | |
| 118 // / "Sep" / "Oct" / "Nov" / "Dec" | |
| 119 // | |
| 120 // time = hour zone ; ANSI and Military | |
| 121 // | |
| 122 // hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT] | |
| 123 // ; 00:00:00 - 23:59:59 | |
| 124 // | |
| 125 // zone = "UT" / "GMT" ; Universal Time | |
| 126 // ; North American : UT | |
| 127 // / "EST" / "EDT" ; Eastern: - 5/ - 4 | |
| 128 // / "CST" / "CDT" ; Central: - 6/ - 5 | |
| 129 // / "MST" / "MDT" ; Mountain: - 7/ - 6 | |
| 130 // / "PST" / "PDT" ; Pacific: - 8/ - 7 | |
| 131 // / 1ALPHA ; Military: Z = UT; | |
| 132 // ; A:-1; (J not used) | |
| 133 // ; M:-12; N:+1; Y:+12 | |
| 134 // / ( ("+" / "-") 4DIGIT ) ; Local differential | |
| 135 // ; hours+min. (HHMM) | |
| 136 // return local time if ret_local_time == true, | |
| 137 // return time is GMT / UTC time otherwise | |
| 138 bool RFC822DateToSystemTime(const TCHAR* str_RFC822_date, | |
| 139 SYSTEMTIME* psys_time, | |
| 140 bool ret_local_time); | |
| 141 | |
| 142 // TODO(omaha): overlap in functionality with FileTimeToTime64. Consider | |
| 143 // removing this one. | |
| 144 inline int64 FileTimeToInt64(const FILETIME& filetime) { | |
| 145 LARGE_INTEGER large_int = {filetime.dwLowDateTime, filetime.dwHighDateTime}; | |
| 146 return large_int.QuadPart; | |
| 147 } | |
| 148 | |
| 149 } // namespace omaha | |
| 150 | |
| 151 #endif // OMAHA_BASE_TIME_H_ | |
| OLD | NEW |