OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 #include "base/time/time.h" | 5 #include "base/time/time.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #include <time.h> | 9 #include <time.h> |
10 #if defined(OS_ANDROID) && !defined(__LP64__) | 10 #if defined(OS_ANDROID) && !defined(__LP64__) |
11 #include <time64.h> | 11 #include <time64.h> |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 milliseconds = min_seconds * kMillisecondsPerSecond; | 294 milliseconds = min_seconds * kMillisecondsPerSecond; |
295 } else { | 295 } else { |
296 milliseconds = max_seconds * kMillisecondsPerSecond; | 296 milliseconds = max_seconds * kMillisecondsPerSecond; |
297 milliseconds += (kMillisecondsPerSecond - 1); | 297 milliseconds += (kMillisecondsPerSecond - 1); |
298 } | 298 } |
299 } else { | 299 } else { |
300 milliseconds = seconds * kMillisecondsPerSecond + exploded.millisecond; | 300 milliseconds = seconds * kMillisecondsPerSecond + exploded.millisecond; |
301 } | 301 } |
302 | 302 |
303 // Adjust from Unix (1970) to Windows (1601) epoch. | 303 // Adjust from Unix (1970) to Windows (1601) epoch. |
304 return Time((milliseconds * kMicrosecondsPerMillisecond) + | 304 base::Time t_time = Time((milliseconds * kMicrosecondsPerMillisecond) + |
305 kWindowsEpochDeltaMicroseconds); | 305 kWindowsEpochDeltaMicroseconds); |
| 306 // If |exploded.day_of_month| is set to 31 |
| 307 // on a 28-30 day month, it will return the first day of the next month. |
| 308 // Thus round-trip the time and compare the initial |exploded| with |
| 309 // |utc_to_exploded| time. |
| 310 // If they are not same, return Time(0). |
| 311 // Windows and Mac implementations return Time(0) on failure. |
| 312 base::Time::Exploded to_exploded = {0}; |
| 313 if (!is_local) |
| 314 t_time.UTCExplode(&to_exploded); |
| 315 else |
| 316 t_time.LocalExplode(&to_exploded); |
| 317 |
| 318 return to_exploded != exploded ? Time(0) : t_time; |
306 } | 319 } |
307 | 320 |
308 // TimeTicks ------------------------------------------------------------------ | 321 // TimeTicks ------------------------------------------------------------------ |
309 // static | 322 // static |
310 TimeTicks TimeTicks::Now() { | 323 TimeTicks TimeTicks::Now() { |
311 return TimeTicks(ClockNow(CLOCK_MONOTONIC)); | 324 return TimeTicks(ClockNow(CLOCK_MONOTONIC)); |
312 } | 325 } |
313 | 326 |
314 // static | 327 // static |
315 TimeTicks::Clock TimeTicks::GetClock() { | 328 TimeTicks::Clock TimeTicks::GetClock() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 372 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
360 return result; | 373 return result; |
361 } | 374 } |
362 int64_t us = us_ - kTimeTToMicrosecondsOffset; | 375 int64_t us = us_ - kTimeTToMicrosecondsOffset; |
363 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 376 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
364 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 377 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
365 return result; | 378 return result; |
366 } | 379 } |
367 | 380 |
368 } // namespace base | 381 } // namespace base |
OLD | NEW |