Skip to content

Commit

Permalink
"Ad notifications received" should show Ads viewed between the 1st of…
Browse files Browse the repository at this point in the history
… the month and the 4th of the following month

fixes brave/brave-browser#3958
  • Loading branch information
tmancey authored Apr 2, 2019
1 parent a9d83ae commit 01c7333
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1491,25 +1491,37 @@ void RewardsServiceImpl::SetCatalogIssuers(const std::string& json) {
}

std::pair<uint64_t, uint64_t> 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) {
Expand Down

0 comments on commit 01c7333

Please sign in to comment.