diff --git a/utils/api/definitions/textReplacementRules.ts b/utils/api/definitions/textReplacementRules.ts index 092bc3692..cd742d465 100644 --- a/utils/api/definitions/textReplacementRules.ts +++ b/utils/api/definitions/textReplacementRules.ts @@ -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) => @@ -134,6 +135,17 @@ export function generateLink(link: Link, opensNewWindow?: string): string { return `${link.text}` } +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 } diff --git a/utils/api/futureHandler.ts b/utils/api/futureHandler.ts index 385377165..2d96efb89 100644 --- a/utils/api/futureHandler.ts +++ b/utils/api/futureHandler.ts @@ -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) diff --git a/utils/api/helpers/utils.ts b/utils/api/helpers/utils.ts index 0cd9d6cc4..8675c968e 100644 --- a/utils/api/helpers/utils.ts +++ b/utils/api/helpers/utils.ts @@ -222,7 +222,7 @@ export function OasEligibility( age++ yearsInCanada++ } - ageOfEligibility = Math.floor(age) + ageOfEligibility = age yearsOfResAtEligibility = livingCountry == 'CAN' ? Math.round(ageOfEligibility - ageAtStart + yearsInCanadaAtStart)