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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 */ | 66 */ |
67 | 67 |
68 #include "base/logging.h" | 68 #include "base/logging.h" |
69 #include "base/third_party/nspr/prtime.h" | 69 #include "base/third_party/nspr/prtime.h" |
70 #include "build/build_config.h" | 70 #include "build/build_config.h" |
71 | 71 |
72 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
73 #include <windows.h> | 73 #include <windows.h> |
74 #elif defined(OS_MACOSX) | 74 #elif defined(OS_MACOSX) |
75 #include <CoreFoundation/CoreFoundation.h> | 75 #include <CoreFoundation/CoreFoundation.h> |
76 #include "base/mac/scoped_cftyperef.h" | |
76 #elif defined(OS_ANDROID) | 77 #elif defined(OS_ANDROID) |
77 #include <ctype.h> | 78 #include <ctype.h> |
78 #include "base/os_compat_android.h" // For timegm() | 79 #include "base/os_compat_android.h" // For timegm() |
79 #elif defined(OS_NACL) | 80 #elif defined(OS_NACL) |
80 #include "base/os_compat_nacl.h" // For timegm() | 81 #include "base/os_compat_nacl.h" // For timegm() |
81 #endif | 82 #endif |
82 #include <errno.h> /* for EINVAL */ | 83 #include <errno.h> /* for EINVAL */ |
83 #include <time.h> | 84 #include <time.h> |
84 | 85 |
85 /* Implements the Unix localtime_r() function for windows */ | 86 /* Implements the Unix localtime_r() function for windows */ |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 // to microsecond units. | 132 // to microsecond units. |
132 PRTime result = | 133 PRTime result = |
133 static_cast<PRTime>((uli.QuadPart / 10) - 11644473600000000i64); | 134 static_cast<PRTime>((uli.QuadPart / 10) - 11644473600000000i64); |
134 // Adjust for time zone and dst. Convert from seconds to microseconds. | 135 // Adjust for time zone and dst. Convert from seconds to microseconds. |
135 result -= (exploded->tm_params.tp_gmt_offset + | 136 result -= (exploded->tm_params.tp_gmt_offset + |
136 exploded->tm_params.tp_dst_offset) * kSecondsToMicroseconds; | 137 exploded->tm_params.tp_dst_offset) * kSecondsToMicroseconds; |
137 // Add microseconds that cannot be represented in |st|. | 138 // Add microseconds that cannot be represented in |st|. |
138 result += exploded->tm_usec % 1000; | 139 result += exploded->tm_usec % 1000; |
139 return result; | 140 return result; |
140 #elif defined(OS_MACOSX) | 141 #elif defined(OS_MACOSX) |
141 // Create the system struct representing our exploded time. | |
142 CFGregorianDate gregorian_date; | |
143 gregorian_date.year = exploded->tm_year; | |
144 gregorian_date.month = exploded->tm_month + 1; | |
145 gregorian_date.day = exploded->tm_mday; | |
146 gregorian_date.hour = exploded->tm_hour; | |
147 gregorian_date.minute = exploded->tm_min; | |
148 gregorian_date.second = exploded->tm_sec; | |
149 | |
150 // Compute |absolute_time| in seconds, correct for gmt and dst | 142 // Compute |absolute_time| in seconds, correct for gmt and dst |
151 // (note the combined offset will be negative when we need to add it), then | 143 // (note the combined offset will be negative when we need to add it), then |
152 // convert to microseconds which is what PRTime expects. | 144 // convert to microseconds which is what PRTime expects. |
153 CFAbsoluteTime absolute_time = | 145 base::ScopedCFTypeRef<CFCalendarRef> gregorian( |
154 CFGregorianDateGetAbsoluteTime(gregorian_date, NULL); | 146 CFCalendarCreateWithIdentifier(kCFAllocatorDefault, |
147 kCFGregorianCalendar)); | |
148 base::ScopedCFTypeRef<CFTimeZoneRef> time_zone( | |
149 CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorDefault, 0)); | |
150 CFCalendarSetTimeZone(gregorian, time_zone); | |
151 CFAbsoluteTime absolute_time; | |
152 CFCalendarComposeAbsoluteTime(gregorian, &absolute_time, "yMdHms", | |
153 static_cast<int>(exploded->tm_year), | |
154 static_cast<int>(exploded->tm_month + 1), | |
155 static_cast<int>(exploded->tm_mday), | |
156 static_cast<int>(exploded->tm_hour), | |
157 static_cast<int>(exploded->tm_min), | |
Nico
2015/12/04 20:18:59
I looked at upstream NSPR to see if they have this
pkl (ping after 24h if needed)
2016/02/03 06:42:31
This change has been moved to https://codereview.c
| |
158 static_cast<int>(exploded->tm_sec)); | |
155 PRTime result = static_cast<PRTime>(absolute_time); | 159 PRTime result = static_cast<PRTime>(absolute_time); |
156 result -= exploded->tm_params.tp_gmt_offset + | 160 result -= exploded->tm_params.tp_gmt_offset + |
157 exploded->tm_params.tp_dst_offset; | 161 exploded->tm_params.tp_dst_offset; |
158 result += kCFAbsoluteTimeIntervalSince1970; // PRTime epoch is 1970 | 162 result += kCFAbsoluteTimeIntervalSince1970; // PRTime epoch is 1970 |
159 result *= kSecondsToMicroseconds; | 163 result *= kSecondsToMicroseconds; |
160 result += exploded->tm_usec; | 164 result += exploded->tm_usec; |
161 return result; | 165 return result; |
162 #elif defined(OS_POSIX) | 166 #elif defined(OS_POSIX) |
163 struct tm exp_tm = {0}; | 167 struct tm exp_tm = {0}; |
164 exp_tm.tm_sec = exploded->tm_sec; | 168 exp_tm.tm_sec = exploded->tm_sec; |
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 + 60 * localTime.tm_hour | 1247 + 60 * localTime.tm_hour |
1244 + 1440 * (localTime.tm_mday - 2); | 1248 + 1440 * (localTime.tm_mday - 2); |
1245 } | 1249 } |
1246 | 1250 |
1247 result->tm_params.tp_gmt_offset = zone_offset * 60; | 1251 result->tm_params.tp_gmt_offset = zone_offset * 60; |
1248 result->tm_params.tp_dst_offset = dst_offset * 60; | 1252 result->tm_params.tp_dst_offset = dst_offset * 60; |
1249 | 1253 |
1250 *result_imploded = PR_ImplodeTime(result); | 1254 *result_imploded = PR_ImplodeTime(result); |
1251 return PR_SUCCESS; | 1255 return PR_SUCCESS; |
1252 } | 1256 } |
OLD | NEW |