From c23e980d72b8155e54c7e2a9b3bd85ef805f5348 Mon Sep 17 00:00:00 2001 From: Ngou Long Kam <25244131+ngoulongkam@users.noreply.github.com> Date: Fri, 20 Mar 2020 11:36:51 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20first=20term=20calculator=20to=20use=20co?= =?UTF-8?q?rrect=20date=20to=20calculate=20remaining=20=E2=80=A6=20(#6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix first term calculator to use correct date to calculate remaining months * Address comment --- README.md | 2 +- .../hmrc/helptosavecalculator/FirstBonusTermCalculation.kt | 6 +++--- .../gov/hmrc/helptosavecalculator/models/FirstBonusInput.kt | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 032ca3b..0d139e3 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Where `input` have the following object: regularPayment: Double, // 25.0 currentBalance: Double, // 25.0 paidInThisMonth: Double, // 50.0 -accountStartDate: YearMonthDayInput, // YearMonthDayInput(2020, 3) +thisMonthEndDate: YearMonthDayInput, // YearMonthDayInput(2020, 3, 31) firstTermEndDate: YearMonthDayInput, // YearMonthDayInput(2022, 2, 28) secondTermEndDate: YearMonthDayInput, // YearMonthDayInput(2024, 2, 28) balanceMustBeMoreThanForBonus: Double // 50.0 diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt index cdda6d7..cdcedab 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt @@ -87,11 +87,11 @@ internal class FirstBonusTermCalculation { } fun calculateMonthsLeftInScheme(input: FirstBonusInput): Pair { - val startDate = input.accountStartDate.convertToDateTime() + val thisMonthEndDate = input.thisMonthEndDate.convertToDateTime() val secondTermEndDate = input.secondTermEndDate.convertToDateTime() val firstTermEndDate = input.firstTermEndDate.convertToDateTime() - val monthsLeftInScheme = startDate.monthsSince(secondTermEndDate) - val monthsLeftInFirstTerm = startDate.monthsSince(firstTermEndDate) + val monthsLeftInScheme = thisMonthEndDate.monthsSince(secondTermEndDate) + val monthsLeftInFirstTerm = thisMonthEndDate.monthsSince(firstTermEndDate) return Pair(monthsLeftInScheme, monthsLeftInFirstTerm) } } diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/FirstBonusInput.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/FirstBonusInput.kt index 1cb19c8..e9731da 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/FirstBonusInput.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/FirstBonusInput.kt @@ -19,7 +19,7 @@ data class FirstBonusInput( val regularPayment: Double, val currentBalance: Double, val paidInThisMonth: Double, - val accountStartDate: YearMonthDayInput, + val thisMonthEndDate: YearMonthDayInput, val firstTermEndDate: YearMonthDayInput, val secondTermEndDate: YearMonthDayInput, val balanceMustBeMoreThanForBonus: Double