Skip to content

Commit a6a7d18

Browse files
add configuration for benefits payment period boundaries (#232)
* add configuration for benefits payment period boundaries
1 parent 42c283a commit a6a7d18

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

frontend/.env.example

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ OTEL_USE_CONSOLE_TRACE_EXPORTER=
142142
# Estimator configuration
143143
#################################################
144144

145+
# Benefits payments period start date shown on index page (YYYY-MM-DD)
146+
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START=
147+
148+
# Benefits payments period end date shown on index page (YYYY-MM-DD)
149+
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END=
150+
145151
# Canada Disability Benefit english contact URL
146152
ESTIMATOR_CDB_CONTACT_URL_EN=
147153

frontend/app/.server/environment/estimator.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import * as v from 'valibot';
22

33
import { stringToBooleanSchema } from '../validation/string-to-boolean-schema';
4+
import { stringToIsoDateSchema } from '../validation/string-to-iso-date-schema';
45
import { stringToNumberSchema } from '../validation/string-to-number-schema';
56
import { stringToUrlSchema } from '../validation/string-to-url-schema';
67

78
// Default estimator configuration object
89
export const defaults = {
10+
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START: '2025-07-01',
11+
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END: '2026-06-01',
912
ESTIMATOR_CDB_CONTACT_URL_EN: undefined,
1013
ESTIMATOR_CDB_CONTACT_URL_FR: undefined,
1114
ESTIMATOR_CDB_URL_EN: 'https://www.canada.ca/en/services/benefits/disability/canada-disability-benefit.html',
@@ -30,6 +33,20 @@ export const defaults = {
3033

3134
// Define schema for the environment variable
3235
export const estimator = v.object({
36+
/**
37+
* Benefits payments period start date shown on index page (YYYY-MM-DD)
38+
*/
39+
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START: v.optional(
40+
stringToIsoDateSchema(),
41+
defaults.ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START,
42+
),
43+
/**
44+
* Benefits payments period end date shown on index page (YYYY-MM-DD)
45+
*/
46+
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END: v.optional(
47+
stringToIsoDateSchema(),
48+
defaults.ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END,
49+
),
3350
/**
3451
* Canada Disability Benefit english contact URL
3552
*/

frontend/app/.server/locales/estimator-en.json

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"result-disclaimer": "<strong>This tool provides an estimate only. It doesn't guarantee that you'll be eligible or that you'll receive the amount estimated.</strong>",
118118
"results": {
119119
"contact": " For a more accurate assessment of your estimated benefits amount, please <cdbContactLink>contact us</cdbContactLink>.",
120+
"description": "This estimator provides estimated benefit amounts for payments made between {{paymentPeriodStart}} and {{paymentPeriodEnd}}. Future benefit amounts may be higher. The results are not financial advice and are subject to change.",
120121
"description": "This estimator provides estimated benefit amounts for payments made between July 2025 and June 2026. Future benefit amounts may be higher. The results are not financial advice and are subject to change.",
121122
"header": "About the results"
122123
}

frontend/app/.server/locales/estimator-fr.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"result-disclaimer": "<strong>Cet outil fournit une estimation seulement. Il ne garantit pas que vous serez admissible ou que vous recevrez le montant estimé.</strong>",
118118
"results": {
119119
"contact": " Pour une évaluation plus précise de votre montant de prestations estimé, veuillez <cdbContactLink>communiquer avec nous</cdbContactLink>.",
120-
"description": "Cet estimateur fournit des montants estimés de prestation pour les paiements effectués entre juillet 2025 et juin 2026. Les montants des prestations futures pourraient être plus élevés en raison de l'inflation. Les résultats ne sont pas des conseils financiers et peuvent changer.",
120+
"description": "Cet estimateur fournit des montants estimés de prestation pour les paiements effectués entre {{paymentPeriodStart}} et {{paymentPeriodEnd}}. Les montants des prestations futures pourraient être plus élevés en raison de l'inflation. Les résultats ne sont pas des conseils financiers et peuvent changer.",
121121
"header": "À propos des résultats"
122122
}
123123
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as v from 'valibot';
2+
3+
export function stringToIsoDateSchema(): v.GenericSchema<string, string> {
4+
return v.pipe(v.string(), v.isoDate());
5+
}

frontend/app/routes/index.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,21 @@ export async function loader({ request }: Route.LoaderArgs) {
3232
};
3333
}
3434

35+
function formatBenefitPaymentsPeriodDate(date: Date, lang: 'fr' | 'en' | undefined) {
36+
const options: Intl.DateTimeFormatOptions = {
37+
year: 'numeric',
38+
month: 'long',
39+
timeZone: 'UTC',
40+
};
41+
42+
return date.toLocaleDateString(lang === 'fr' ? 'fr-CA' : 'en-CA', options);
43+
}
44+
3545
export default function Home({ loaderData }: Route.ComponentProps) {
3646
const { t, i18n } = useTranslation(handle.i18nNamespace);
3747
const {
48+
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START,
49+
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END,
3850
ESTIMATOR_CDB_CONTACT_URL_EN,
3951
ESTIMATOR_CDB_CONTACT_URL_FR,
4052
ESTIMATOR_CDB_ELIGIBILITY_URL_EN,
@@ -106,7 +118,16 @@ export default function Home({ loaderData }: Route.ComponentProps) {
106118
<section className="space-y-4">
107119
<h2 className="font-lato text-lg font-bold">{t('estimator:index.content.results.header')}</h2>
108120
<p>
109-
<Trans ns={handle.i18nNamespace} i18nKey="estimator:index.content.results.description" />
121+
{t('estimator:index.content.results.description', {
122+
paymentPeriodStart: formatBenefitPaymentsPeriodDate(
123+
new Date(ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START),
124+
i18n.language,
125+
),
126+
paymentPeriodEnd: formatBenefitPaymentsPeriodDate(
127+
new Date(ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END),
128+
i18n.language,
129+
),
130+
})}
110131

111132
{i18n.language === 'fr' && ESTIMATOR_CDB_CONTACT_URL_FR && (
112133
<Trans

0 commit comments

Comments
 (0)