Skip to content

Commit

Permalink
dont round the future age to get accurate age at first eligibility (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-solo authored Jun 6, 2024
1 parent 4231619 commit a0c663e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion utils/api/definitions/textReplacementRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export const textReplacementRules: TextReplacementRules = {
handler.fields.input.client.maritalStatus.partnered
? handler.fields.translations.incomeCombined
: handler.fields.translations.incomeSingle,
EARLIEST_ELIGIBLE_AGE: (handler) => String(handler.rawInput.age),
EARLIEST_ELIGIBLE_AGE: (handler) =>
getEligibleAgeWithMonths(handler.rawInput.age),
LINK_SERVICE_CANADA: (handler) =>
generateLink(handler.fields.translations.links.SC),
MY_SERVICE_CANADA: (handler) =>
Expand Down Expand Up @@ -134,6 +135,17 @@ export function generateLink(link: Link, opensNewWindow?: string): string {
return `<a class="underline text-default-text generatedLink" href="${link.url}" target="_blank">${link.text}</a>`
}

export function getEligibleAgeWithMonths(age: number) {
if (Number.isInteger(age)) {
return age.toString()
}

const years = Math.floor(age)
const months = Math.round((age - years) * 12)

return `${years} years and ${months} months`
}

export function getMaxYear(): number {
return new Date().getFullYear() - 18
}
Expand Down
1 change: 1 addition & 0 deletions utils/api/futureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class FutureHandler {
this.query.livedOnlyInCanada === 'true',
String(this.query.livingCountry)
)

const oasAge = eliObjOas.ageOfEligibility

const eliObjAlws = AlwsEligibility(Math.floor(age), yearsInCanada)
Expand Down
2 changes: 1 addition & 1 deletion utils/api/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function OasEligibility(
age++
yearsInCanada++
}
ageOfEligibility = Math.floor(age)
ageOfEligibility = age
yearsOfResAtEligibility =
livingCountry == 'CAN'
? Math.round(ageOfEligibility - ageAtStart + yearsInCanadaAtStart)
Expand Down

0 comments on commit a0c663e

Please sign in to comment.