From 633fadec3a8a414b5a1a8f5e4fdf66bf888d0883 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Mon, 1 Apr 2019 21:59:26 +0100 Subject: [PATCH] "Ad notifications received" should show Ads viewed between the 1st of the month and the 4th of the following month --- .../browser/rewards_service_impl.cc | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 0273c878a6fb..fb72b9af90c4 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -1460,25 +1460,37 @@ void RewardsServiceImpl::SetCatalogIssuers(const std::string& json) { } std::pair RewardsServiceImpl::GetEarningsRange() { - auto one_day_in_seconds = base::Time::kMicrosecondsPerDay / - base::Time::kMicrosecondsPerSecond; - auto now = base::Time::Now(); base::Time::Exploded exploded; now.LocalExplode(&exploded); - uint64_t offset_in_seconds; - if (exploded.day_of_month > 5) { - offset_in_seconds = (exploded.day_of_month - 5) * one_day_in_seconds; - } else { - offset_in_seconds = exploded.day_of_month * one_day_in_seconds; + if (exploded.day_of_month < 5) { + exploded.month--; + if (exploded.month < 1) { + exploded.month = 12; + + exploded.year--; + } } - auto now_in_seconds = (now - base::Time()).InSeconds(); - uint64_t from_timestamp = now_in_seconds - offset_in_seconds; - uint64_t to_timestamp = now_in_seconds; + exploded.day_of_month = 1; + + exploded.hour = 0; + exploded.minute = 0; + exploded.second = 0; + exploded.millisecond = 0; + + base::Time from_timestamp; + auto success = base::Time::FromLocalExploded(exploded, &from_timestamp); + DCHECK(success); + + uint64_t from_timestamp_in_seconds = + (from_timestamp - base::Time()).InSeconds(); + + uint64_t to_timestamp_in_seconds = + (now - base::Time()).InSeconds(); - return std::make_pair(from_timestamp, to_timestamp); + return std::make_pair(from_timestamp_in_seconds, to_timestamp_in_seconds); } void RewardsServiceImpl::ConfirmAd(const std::string& json) {