Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* Portions are Copyright (C) 2011 Google Inc */ | 1 /* Portions are Copyright (C) 2011 Google Inc */ |
| 2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
| 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 4 * | 4 * |
| 5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
| 6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
| 7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
| 8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
| 9 * | 9 * |
| 10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 */ | 64 */ |
| 65 | 65 |
| 66 #include "base/logging.h" | 66 #include "base/logging.h" |
| 67 #include "base/third_party/nspr/prtime.h" | 67 #include "base/third_party/nspr/prtime.h" |
| 68 #include "build/build_config.h" | 68 #include "build/build_config.h" |
| 69 | 69 |
| 70 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
| 71 #include <windows.h> | 71 #include <windows.h> |
| 72 #elif defined(OS_MACOSX) | 72 #elif defined(OS_MACOSX) |
| 73 #include <CoreFoundation/CoreFoundation.h> | 73 #include <CoreFoundation/CoreFoundation.h> |
| 74 #elif defined(OS_ANDROID) | |
| 75 #include <ctype.h> | |
| 76 #include "base/time.h" // For timegm() | |
|
brettw
2011/08/24 20:46:58
I'm surprised you have to include Chrome's time.h
michaelbai
2011/08/24 23:02:18
Sorry, it seemed I should upload more files, timeg
| |
| 74 #endif | 77 #endif |
| 75 #include <errno.h> /* for EINVAL */ | 78 #include <errno.h> /* for EINVAL */ |
| 76 #include <time.h> | 79 #include <time.h> |
| 77 | 80 |
| 78 /* Implements the Unix localtime_r() function for windows */ | 81 /* Implements the Unix localtime_r() function for windows */ |
| 79 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
| 80 static void localtime_r(const time_t* secs, struct tm* time) { | 83 static void localtime_r(const time_t* secs, struct tm* time) { |
| 81 (void) localtime_s(time, secs); | 84 (void) localtime_s(time, secs); |
| 82 } | 85 } |
| 83 #endif | 86 #endif |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 #elif defined(OS_MACOSX) | 134 #elif defined(OS_MACOSX) |
| 132 // Create the system struct representing our exploded time. | 135 // Create the system struct representing our exploded time. |
| 133 CFGregorianDate gregorian_date; | 136 CFGregorianDate gregorian_date; |
| 134 gregorian_date.year = exploded->tm_year; | 137 gregorian_date.year = exploded->tm_year; |
| 135 gregorian_date.month = exploded->tm_month + 1; | 138 gregorian_date.month = exploded->tm_month + 1; |
| 136 gregorian_date.day = exploded->tm_mday; | 139 gregorian_date.day = exploded->tm_mday; |
| 137 gregorian_date.hour = exploded->tm_hour; | 140 gregorian_date.hour = exploded->tm_hour; |
| 138 gregorian_date.minute = exploded->tm_min; | 141 gregorian_date.minute = exploded->tm_min; |
| 139 gregorian_date.second = exploded->tm_sec; | 142 gregorian_date.second = exploded->tm_sec; |
| 140 | 143 |
| 141 // Compute |absolute_time| in seconds, correct for gmt and dst | 144 // Compute |absolute_time| in seconds, correct for gmt and dst |
| 142 // (note the combined offset will be negative when we need to add it), then | 145 // (note the combined offset will be negative when we need to add it), then |
| 143 // convert to microseconds which is what PRTime expects. | 146 // convert to microseconds which is what PRTime expects. |
| 144 CFAbsoluteTime absolute_time = | 147 CFAbsoluteTime absolute_time = |
| 145 CFGregorianDateGetAbsoluteTime(gregorian_date, NULL); | 148 CFGregorianDateGetAbsoluteTime(gregorian_date, NULL); |
| 146 PRTime result = static_cast<PRTime>(absolute_time); | 149 PRTime result = static_cast<PRTime>(absolute_time); |
| 147 result -= exploded->tm_params.tp_gmt_offset + | 150 result -= exploded->tm_params.tp_gmt_offset + |
| 148 exploded->tm_params.tp_dst_offset; | 151 exploded->tm_params.tp_dst_offset; |
| 149 result += kCFAbsoluteTimeIntervalSince1970; // PRTime epoch is 1970 | 152 result += kCFAbsoluteTimeIntervalSince1970; // PRTime epoch is 1970 |
| 150 result *= kSecondsToMicroseconds; | 153 result *= kSecondsToMicroseconds; |
| 151 result += exploded->tm_usec; | 154 result += exploded->tm_usec; |
| 152 return result; | 155 return result; |
| 153 #elif defined(OS_POSIX) | 156 #elif defined(OS_POSIX) |
| 154 struct tm exp_tm = {0}; | 157 struct tm exp_tm = {0}; |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 + 60 * localTime.tm_hour | 1198 + 60 * localTime.tm_hour |
| 1196 + 1440 * (localTime.tm_mday - 2); | 1199 + 1440 * (localTime.tm_mday - 2); |
| 1197 } | 1200 } |
| 1198 | 1201 |
| 1199 result->tm_params.tp_gmt_offset = zone_offset * 60; | 1202 result->tm_params.tp_gmt_offset = zone_offset * 60; |
| 1200 result->tm_params.tp_dst_offset = dst_offset * 60; | 1203 result->tm_params.tp_dst_offset = dst_offset * 60; |
| 1201 | 1204 |
| 1202 *result_imploded = PR_ImplodeTime(result); | 1205 *result_imploded = PR_ImplodeTime(result); |
| 1203 return PR_SUCCESS; | 1206 return PR_SUCCESS; |
| 1204 } | 1207 } |
| OLD | NEW |