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

Fixes next payment date appearing as 4th instead of 5th for a user in Australia on Android #4176

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -947,14 +947,14 @@ uint64_t ConfirmationsImpl::GetAdNotificationsReceivedThisMonthForTransactions(

auto now = base::Time::Now();
base::Time::Exploded now_exploded;
now.LocalExplode(&now_exploded);
now.UTCExplode(&now_exploded);

for (const auto& transaction : transactions) {
auto transaction_timestamp =
Time::FromDoubleT(transaction.timestamp_in_seconds);

base::Time::Exploded transaction_timestamp_exploded;
transaction_timestamp.LocalExplode(&transaction_timestamp_exploded);
transaction_timestamp.UTCExplode(&transaction_timestamp_exploded);

if (transaction_timestamp_exploded.year == now_exploded.year &&
transaction_timestamp_exploded.month == now_exploded.month &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ base::Time Payments::CalculateNextPaymentDate(
const base::Time& time,
const uint64_t next_token_redemption_date_in_seconds) const {
base::Time::Exploded now_exploded;
time.LocalExplode(&now_exploded);
time.UTCExplode(&now_exploded);

int month = now_exploded.month;

Expand All @@ -153,7 +153,7 @@ base::Time Payments::CalculateNextPaymentDate(
Time::FromDoubleT(next_token_redemption_date_in_seconds);

base::Time::Exploded next_token_redemption_date_exploded;
next_token_redemption_date.LocalExplode(
next_token_redemption_date.UTCExplode(
&next_token_redemption_date_exploded);

if (next_token_redemption_date_exploded.month == month) {
Expand All @@ -177,10 +177,18 @@ base::Time Payments::CalculateNextPaymentDate(
year++;
}

auto date = base::StringPrintf("%d-%d-%d", year, month, kNextPaymentDay);
base::Time::Exploded next_payment_date_exploded = now_exploded;
next_payment_date_exploded.year = year;
next_payment_date_exploded.month = month;
next_payment_date_exploded.day_of_month = kNextPaymentDay;
next_payment_date_exploded.hour = 23;
next_payment_date_exploded.minute = 59;
next_payment_date_exploded.second = 59;
next_payment_date_exploded.millisecond = 999;

base::Time next_payment_date;
bool success = base::Time::FromString(date.c_str(), &next_payment_date);
bool success = base::Time::FromUTCExploded(next_payment_date_exploded,
&next_payment_date);
DCHECK(success);

return next_payment_date;
Expand Down Expand Up @@ -321,15 +329,15 @@ PaymentInfo Payments::GetPaymentForTransactionMonth(

std::string Payments::GetTransactionMonth(const base::Time& time) const {
base::Time::Exploded time_exploded;
time.LocalExplode(&time_exploded);
time.UTCExplode(&time_exploded);

return GetFormattedTransactionMonth(time_exploded.year, time_exploded.month);
}

std::string Payments::GetPreviousTransactionMonth(
const base::Time& time) const {
base::Time::Exploded time_exploded;
time.LocalExplode(&time_exploded);
time.UTCExplode(&time_exploded);

time_exploded.month--;
if (time_exploded.month < 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ class ConfirmationsPaymentsTest : public ::testing::Test {
}

// Objects declared here can be used by all tests in the test case
base::Time GetNextPaymentDate(
base::Time GetNextPaymentUTCDate(
const std::string& date,
const std::string& next_token_redemption_date) {
auto current_date = DateFromString(date);
auto current_date = UTCDateFromString(date);

auto token_redemption_date = DateFromString(next_token_redemption_date);
auto token_redemption_date = UTCDateFromString(next_token_redemption_date);
uint64_t token_redemption_date_in_seconds =
token_redemption_date.ToDoubleT();

return payments_->CalculateNextPaymentDate(current_date,
token_redemption_date_in_seconds);
}

base::Time DateFromString(const std::string& date) {
base::Time UTCDateFromString(
const std::string& date) {
const std::string utc_date = date + " 00:00:00 +00:00";

base::Time time;
if (!base::Time::FromString(date.c_str(), &time)) {
if (!base::Time::FromString(utc_date.c_str(), &time)) {
return base::Time();
}

Expand Down Expand Up @@ -126,7 +129,7 @@ TEST_F(ConfirmationsPaymentsTest, InvalidJson_DefaultTransactionCount) {
std::string json = "[{\"balance\":\"0.5\",\"month\":\"2019-06\",\"transactionCount\":\"INVALID\"}]"; // NOLINT
payments_->SetFromJson(json);

auto date = DateFromString("6 July 2019");
auto date = UTCDateFromString("6 July 2019");

// Act
auto transaction_count = payments_->GetTransactionCountForMonth(date);
Expand All @@ -140,7 +143,7 @@ TEST_F(ConfirmationsPaymentsTest, InvalidJsonWrongType_DefaultTransactionCount)
std::string json = "[{\"balance\":\"0.5\",\"month\":\"2019-06\",\"transactionCount\":5}]"; // NOLINT
payments_->SetFromJson(json);

auto date = DateFromString("6 July 2019");
auto date = UTCDateFromString("6 July 2019");

// Act
auto transaction_count = payments_->GetTransactionCountForMonth(date);
Expand Down Expand Up @@ -190,7 +193,7 @@ TEST_F(ConfirmationsPaymentsTest, TransactionCount_ForThisMonth) {
std::string json = "[{\"balance\":\"0.5\",\"month\":\"2019-06\",\"transactionCount\":\"10\"}]"; // NOLINT
payments_->SetFromJson(json);

auto date = DateFromString("6 June 2019");
auto date = UTCDateFromString("6 June 2019");

// Act
auto transaction_count = payments_->GetTransactionCountForMonth(date);
Expand All @@ -204,7 +207,7 @@ TEST_F(ConfirmationsPaymentsTest, TransactionCount_ForThisMonthWithMultiplePayme
std::string json = "[{\"balance\":\"0.5\",\"month\":\"2019-06\",\"transactionCount\":\"10\"},{\"balance\":\"0.25\",\"month\":\"2019-05\",\"transactionCount\":\"5\"}]"; // NOLINT
payments_->SetFromJson(json);

auto date = DateFromString("6 June 2019");
auto date = UTCDateFromString("6 June 2019");

// Act
auto transaction_count = payments_->GetTransactionCountForMonth(date);
Expand All @@ -218,7 +221,7 @@ TEST_F(ConfirmationsPaymentsTest, TransactionCount_ForThisMonthWithMultiplePayme
std::string json = "[{\"balance\":\"0.25\",\"month\":\"2019-05\",\"transactionCount\":\"5\"},{\"balance\":\"0.5\",\"month\":\"2019-06\",\"transactionCount\":\"10\"}]"; // NOLINT
payments_->SetFromJson(json);

auto date = DateFromString("6 June 2019");
auto date = UTCDateFromString("6 June 2019");

// Act
auto transaction_count = payments_->GetTransactionCountForMonth(date);
Expand All @@ -236,10 +239,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_BeforeNextPaymentDate
std::string next_token_redemption_date = "21 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 July 2019");
auto expected_next_payment_date = UTCDateFromString("5 July 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -252,10 +256,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_BeforeNextPaymentDate
std::string next_token_redemption_date = "21 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 July 2019");
auto expected_next_payment_date = UTCDateFromString("5 July 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -268,10 +273,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_BeforeNextPaymentDate
std::string next_token_redemption_date = "21 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 August 2019");
auto expected_next_payment_date = UTCDateFromString("5 August 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -284,10 +290,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_BeforeNextPaymentDate
std::string next_token_redemption_date = "21 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 August 2019");
auto expected_next_payment_date = UTCDateFromString("5 August 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -300,10 +307,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_BeforeNextPaymentDate
std::string next_token_redemption_date = "21 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 August 2019");
auto expected_next_payment_date = UTCDateFromString("5 August 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -316,10 +324,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_AfterNextPaymentDate_
std::string next_token_redemption_date = "28 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 August 2019");
auto expected_next_payment_date = UTCDateFromString("5 August 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -332,10 +341,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_AfterNextPaymentDate_
std::string next_token_redemption_date = "28 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 August 2019");
auto expected_next_payment_date = UTCDateFromString("5 August 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -348,10 +358,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_AfterNextPaymentDate_
std::string next_token_redemption_date = "15 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 August 2019");
auto expected_next_payment_date = UTCDateFromString("5 August 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -364,10 +375,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_AfterNextPaymentDate_
std::string next_token_redemption_date = "15 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 August 2019");
auto expected_next_payment_date = UTCDateFromString("5 August 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -380,10 +392,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_AfterNextPaymentDate_
std::string next_token_redemption_date = "15 July 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 August 2019");
auto expected_next_payment_date = UTCDateFromString("5 August 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -396,10 +409,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_AfterNextPaymentDate_
std::string next_token_redemption_date = "15 August 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 September 2019");
auto expected_next_payment_date = UTCDateFromString("5 September 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand All @@ -412,10 +426,11 @@ TEST_F(ConfirmationsPaymentsTest, CalculateNextPaymentDate_AfterNextPaymentDate_
std::string next_token_redemption_date = "15 August 2019";

// Act
auto next_payment_date = GetNextPaymentDate(date, next_token_redemption_date);
auto next_payment_date =
GetNextPaymentUTCDate(date, next_token_redemption_date);

// Assert
auto expected_next_payment_date = DateFromString("5 September 2019");
auto expected_next_payment_date = UTCDateFromString("5 September 2019");
EXPECT_EQ(expected_next_payment_date, next_payment_date);
}

Expand Down