Skip to content

Commit

Permalink
Merge pull request #7924 from brave/ksmith-fix-bap-cutoff
Browse files Browse the repository at this point in the history
Fix BAP date calculation
  • Loading branch information
zenparsing authored Feb 11, 2021
2 parents edac78c + 4306f20 commit 5769e9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1494,8 +1494,9 @@ bool RewardsServiceImpl::GetBooleanOption(const std::string& name) const {
base::Time::Exploded cutoff_exploded{
.year = 2021, .month = 3, .day_of_month = 13};
base::Time cutoff;
DCHECK(base::Time::FromUTCExploded(cutoff_exploded, &cutoff));
if (base::Time::Now() >= cutoff) {
bool ok = base::Time::FromUTCExploded(cutoff_exploded, &cutoff);
DCHECK(ok);
if (ok && base::Time::Now() >= cutoff) {
return true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions components/brave_rewards/browser/test/rewards_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ namespace {

base::Time GetDate(int year, int month, int day_of_month) {
base::Time time;
DCHECK(base::Time::FromUTCExploded(
bool ok = base::Time::FromUTCExploded(
base::Time::Exploded{
.year = year, .month = month, .day_of_month = day_of_month},
&time));
&time);
DCHECK(ok);
return time;
}

Expand Down Expand Up @@ -482,8 +483,7 @@ IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, BAPCutoffBefore) {

{
base::subtle::ScopedTimeClockOverrides time_override(
[]() { return GetDate(2021, 3, 13) - base::TimeDelta::FromSeconds(1); },
nullptr, nullptr);
[]() { return GetDate(2021, 3, 12); }, nullptr, nullptr);
ASSERT_EQ(FetchBalance(), 30.0);
}
}
Expand Down

0 comments on commit 5769e9d

Please sign in to comment.