Skip to content

Commit

Permalink
update date utils (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
faiza-jahanzeb authored Feb 26, 2025
1 parent 31cb99d commit eab81ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 10 additions & 2 deletions frontend/app/routes/protected/person-case/primary-docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export function meta({ data }: Route.MetaArgs) {
return [{ title: data.documentTitle }];
}

function toDateString(year: number, month: number, day: number): string {
try {
return toISODateString(year, month, day);
} catch {
return '';
}
}

export async function action({ context, request }: Route.ActionArgs) {
requireAuth(context.session, new URL(request.url), ['user']);

Expand Down Expand Up @@ -218,12 +226,12 @@ export async function action({ context, request }: Route.ActionArgs) {
const dateOfBirthYear = Number(formData.get('dateOfBirthYear'));
const dateOfBirthMonth = Number(formData.get('dateOfBirthMonth'));
const dateOfBirthDay = Number(formData.get('dateOfBirthDay'));
const dateOfBirth = toISODateString(dateOfBirthYear, dateOfBirthMonth, dateOfBirthDay);
const dateOfBirth = toDateString(dateOfBirthYear, dateOfBirthMonth, dateOfBirthDay);

const citizenshipDateYear = Number(formData.get('citizenshipDateYear'));
const citizenshipDateMonth = Number(formData.get('citizenshipDateMonth'));
const citizenshipDateDay = Number(formData.get('citizenshipDateDay'));
const citizenshipDate = toISODateString(citizenshipDateYear, citizenshipDateMonth, citizenshipDateDay);
const citizenshipDate = toDateString(citizenshipDateYear, citizenshipDateMonth, citizenshipDateDay);

const input = {
currentStatusInCanada: String(formData.get('currentStatusInCanada')),
Expand Down
2 changes: 0 additions & 2 deletions frontend/app/utils/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ export function getStartOfDayInTimezone(timezone: string, date?: number | string
* @returns An ISO 8601 date string in the format "YYYY-MM-DD".
*/
export function toISODateString(year: number, month: number, day: number): string {
if (isNaN(year) || isNaN(month) || isNaN(day)) return '';
if (!dateExists(year, month - 1, day)) return '';
return formatISODate(`${year}-${month}-${day}`);
}

Expand Down

0 comments on commit eab81ea

Please sign in to comment.