Skip to content

Commit

Permalink
fix date test
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-prins committed Dec 31, 2024
1 parent 65acf58 commit 67f2e0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client/packages/common/src/intl/utils/DateUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('getDisplayAge', () => {
const hookResult = renderHookWithProvider(() => useFormatDateTime());
const { getDisplayAge } = hookResult.result.current;
const today = new Date();

it('returns age in years when patient is over 1 year or 1 year old', () => {
const dob = DateUtils.addYears(today, -9);
const result = getDisplayAge(dob);
Expand All @@ -26,9 +27,12 @@ describe('getDisplayAge', () => {

it('returns age in months and days when patient is less than 1 year old', () => {
const threeMonthsAgo = DateUtils.addMonths(today, -3);
const dayOffset =
DateUtils.getDaysInMonth(today) -
DateUtils.getDaysInMonth(threeMonthsAgo);
const dob = DateUtils.addDays(threeMonthsAgo, -2);
const result = getDisplayAge(dob);
expect(result).toBe('3 months, 2 days');
expect(result).toBe(`3 months, ${2 + dayOffset} days`);
});

it('returns age in days when patient is less than 1 month old', () => {
Expand Down
2 changes: 2 additions & 0 deletions client/packages/common/src/intl/utils/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
differenceInMonths,
differenceInMinutes,
differenceInYears,
getDaysInMonth,
isPast,
isFuture,
isThisWeek,
Expand Down Expand Up @@ -104,6 +105,7 @@ export const DateUtils = {
: new Date(date);
return isValid(maybeDate) ? maybeDate : null;
},
getDaysInMonth,
/**
* While getDateOrNull is naive to the timezone, the timezone will still
* change. When converting from the assumed naive zone of GMT to the local
Expand Down

0 comments on commit 67f2e0f

Please sign in to comment.