Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: base/time/time_win.cc

Issue 1988663002: Add: check exploded time is properly converted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« base/time/time_posix.cc ('K') | « base/time/time_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 // Windows Timer Primer 6 // Windows Timer Primer
7 // 7 //
8 // A good article: http://www.ddj.com/windows/184416651 8 // A good article: http://www.ddj.com/windows/184416651
9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258
10 // 10 //
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 success = !!SystemTimeToFileTime(&st, &ft); 259 success = !!SystemTimeToFileTime(&st, &ft);
260 } 260 }
261 261
262 if (!success) { 262 if (!success) {
263 NOTREACHED() << "Unable to convert time"; 263 NOTREACHED() << "Unable to convert time";
264 return Time(0); 264 return Time(0);
265 } 265 }
266 return Time(FileTimeToMicroseconds(ft)); 266 return Time(FileTimeToMicroseconds(ft));
267 } 267 }
268 268
269 // static
270 bool Time::FromExploded(bool is_local, const Exploded& exploded, Time& time) {
271 // Create the system struct representing our exploded time. It will either be
272 // in local time or UTC.
273 SYSTEMTIME st;
274 st.wYear = static_cast<WORD>(exploded.year);
275 st.wMonth = static_cast<WORD>(exploded.month);
276 st.wDayOfWeek = static_cast<WORD>(exploded.day_of_week);
277 st.wDay = static_cast<WORD>(exploded.day_of_month);
278 st.wHour = static_cast<WORD>(exploded.hour);
279 st.wMinute = static_cast<WORD>(exploded.minute);
280 st.wSecond = static_cast<WORD>(exploded.second);
281 st.wMilliseconds = static_cast<WORD>(exploded.millisecond);
282
283 FILETIME ft;
284 bool success = true;
285 // Ensure that it's in UTC.
286 if (is_local) {
287 SYSTEMTIME utc_st;
288 success = TzSpecificLocalTimeToSystemTime(NULL, &st, &utc_st) &&
mmenke 2016/05/20 19:44:57 nit: nullptr is now preferred over NULL.
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
289 SystemTimeToFileTime(&utc_st, &ft);
290 } else {
291 success = !!SystemTimeToFileTime(&st, &ft);
292 }
293
294 if (!success) {
295 NOTREACHED() << "Unable to convert time";
mmenke 2016/05/20 19:44:57 Looks like this NOTREACHED is incorrect (In the ol
maksims (do not use this acc) 2016/05/24 09:14:21 Done.
296 time = Time(0);
297 return false;
298 }
299
300 time = Time(FileTimeToMicroseconds(ft));
301 return true;
302 }
303
269 void Time::Explode(bool is_local, Exploded* exploded) const { 304 void Time::Explode(bool is_local, Exploded* exploded) const {
270 if (us_ < 0LL) { 305 if (us_ < 0LL) {
271 // We are not able to convert it to FILETIME. 306 // We are not able to convert it to FILETIME.
272 ZeroMemory(exploded, sizeof(*exploded)); 307 ZeroMemory(exploded, sizeof(*exploded));
273 return; 308 return;
274 } 309 }
275 310
276 // FILETIME in UTC. 311 // FILETIME in UTC.
277 FILETIME utc_ft; 312 FILETIME utc_ft;
278 MicrosecondsToFileTime(us_, &utc_ft); 313 MicrosecondsToFileTime(us_, &utc_ft);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { 643 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) {
609 return TimeTicks() + QPCValueToTimeDelta(qpc_value); 644 return TimeTicks() + QPCValueToTimeDelta(qpc_value);
610 } 645 }
611 646
612 // TimeDelta ------------------------------------------------------------------ 647 // TimeDelta ------------------------------------------------------------------
613 648
614 // static 649 // static
615 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { 650 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) {
616 return QPCValueToTimeDelta(qpc_value); 651 return QPCValueToTimeDelta(qpc_value);
617 } 652 }
OLDNEW
« base/time/time_posix.cc ('K') | « base/time/time_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698