Commit a6f3247f authored by boriay's avatar boriay Committed by Commit bot

Fix midnight determination

Midnight determination by scaling value of internal base::Time representation doesn't take in account time zones, it counts as UTC, but other time logic in local time.
There is failure of test ChromeNetworkDailyDataSavingMetricsTest.PartialDayTimeChange if system time zone will overcome test time to another day (like our +4 for example).
This fix make it work fine and in same way for win and others operating systems.

R=bolian@chromium.org

BUG=

Review URL: https://codereview.chromium.org/479793002

Cr-Commit-Position: refs/heads/master@{#292589}
parent 6a55ddd7
......@@ -356,18 +356,14 @@ void UpdateContentLengthPrefsForDataReductionProxy(
int64 then_internal = prefs->GetInt64(
data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate);
#if defined(OS_WIN)
base::Time then_midnight = base::Time::FromInternalValue(then_internal);
base::Time midnight =
base::Time::FromInternalValue(
(now.ToInternalValue() / base::Time::kMicrosecondsPerDay) *
base::Time::kMicrosecondsPerDay);
#else
// Local midnight could have been shifted due to time zone change.
base::Time then_midnight =
base::Time::FromInternalValue(then_internal).LocalMidnight();
// If time is null then don't care if midnight will be wrong shifted due to
// time zone change because it's still too much time ago.
base::Time then_midnight = base::Time::FromInternalValue(then_internal);
if (!then_midnight.is_null()) {
then_midnight = then_midnight.LocalMidnight();
}
base::Time midnight = now.LocalMidnight();
#endif
int days_since_last_update = (midnight - then_midnight).InDays();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment