From 4306f20c0378372cc663733143c326eb31b10740 Mon Sep 17 00:00:00 2001 From: zenparsing Date: Wed, 10 Feb 2021 16:08:23 -0500 Subject: [PATCH] Fix BAP cutoff date calculation --- components/brave_rewards/browser/rewards_service_impl.cc | 5 +++-- .../brave_rewards/browser/test/rewards_browsertest.cc | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 73517d622e9d..856a671248de 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -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; } } diff --git a/components/brave_rewards/browser/test/rewards_browsertest.cc b/components/brave_rewards/browser/test/rewards_browsertest.cc index 196dd6733ce5..38b9e908634b 100644 --- a/components/brave_rewards/browser/test/rewards_browsertest.cc +++ b/components/brave_rewards/browser/test/rewards_browsertest.cc @@ -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; } @@ -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); } }