Chromium Code Reviews| Index: base/time/time_mac.cc |
| diff --git a/base/time/time_mac.cc b/base/time/time_mac.cc |
| index c23c4917e757f492ab7a6cc151158a55901878ef..440da64ad49cebb3707e71af43feb01deea247c6 100644 |
| --- a/base/time/time_mac.cc |
| +++ b/base/time/time_mac.cc |
| @@ -34,7 +34,7 @@ int64_t ComputeCurrentTicks() { |
| struct timeval boottime; |
| int mib[2] = {CTL_KERN, KERN_BOOTTIME}; |
| size_t size = sizeof(boottime); |
| - int kr = sysctl(mib, arraysize(mib), &boottime, &size, NULL, 0); |
| + int kr = sysctl(mib, arraysize(mib), &boottime, &size, nullptr, 0); |
| DCHECK_EQ(KERN_SUCCESS, kr); |
| base::TimeDelta time_difference = base::Time::Now() - |
| (base::Time::FromTimeT(boottime.tv_sec) + |
| @@ -168,7 +168,7 @@ Time Time::NowFromSystemTime() { |
| } |
| // static |
| -Time Time::FromExploded(bool is_local, const Exploded& exploded) { |
| +bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) { |
| base::ScopedCFTypeRef<CFTimeZoneRef> time_zone( |
| is_local |
| ? CFTimeZoneCopySystem() |
| @@ -184,8 +184,26 @@ Time Time::FromExploded(bool is_local, const Exploded& exploded) { |
| exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, |
| exploded.millisecond); |
| CFAbsoluteTime seconds = absolute_time + kCFAbsoluteTimeIntervalSince1970; |
| - return Time(static_cast<int64_t>(seconds * kMicrosecondsPerSecond) + |
| - kWindowsEpochDeltaMicroseconds); |
| + |
| + base::Time converted_time = |
| + Time(static_cast<int64_t>(seconds * kMicrosecondsPerSecond) + |
| + kWindowsEpochDeltaMicroseconds); |
| + |
| + // If |exploded.day_of_month| is set to 31 |
| + // on a 28-30 day month, it will return the first day of the next month. |
| + // Thus round-trip the time and compare the initial |exploded| with |
| + // |utc_to_exploded| time. |
| + base::Time::Exploded to_exploded; |
| + if (!is_local) |
| + converted_time.UTCExplode(&to_exploded); |
| + else |
| + converted_time.LocalExplode(&to_exploded); |
| + |
| + *time = to_exploded != exploded ? Time(0) : converted_time; |
| + |
| + // If time is null, return false |
| + // which means time conversion failed |
| + return (*time).is_null() ? false : true; |
|
mmenke
2016/05/24 16:08:33
Time(0) is actually a legal time, so suggest inste
maksims (do not use this acc)
2016/05/26 04:38:18
Done.
|
| } |
| void Time::Explode(bool is_local, Exploded* exploded) const { |