diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 5b3ab1e5cd96..5a2e3427b031 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -1472,25 +1472,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) {