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

dont round the future age to get accurate age at first eligibility #1067

Merged
merged 1 commit into from
Jun 6, 2024
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
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
Loading