Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Ad notifications received" should show Ads viewed between the 1st of the month and the 4th of the following month 0.63.x #2145

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1460,25 +1460,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