diff --git a/libs/shared/src/utils/date-utils.spec.ts b/libs/shared/src/utils/date-utils.spec.ts index bbda444f..147a17d2 100644 --- a/libs/shared/src/utils/date-utils.spec.ts +++ b/libs/shared/src/utils/date-utils.spec.ts @@ -35,17 +35,17 @@ describe('calculateTimeSeriesInterval', () => { describe('converts between years and ages', () => { it.each` - dateOfBirth | currentAge - ${'1995-02-20'} | ${27} - ${new Date('Feb 20 1995')} | ${27} - ${DateTime.fromISO('1995-02-20')} | ${27} - ${null} | ${null} - ${undefined} | ${null} - ${'2022-10-15'} | ${0} - ${'2021-10-12'} | ${1} - ${'2021-10-18'} | ${0} + dateOfBirth | currentAge + ${'1995-02-20'} | ${27} + ${new Date('Feb 20 1995')} | ${27} + ${DateTime.fromISO('1995-02-20', { zone: 'utc' })} | ${27} + ${null} | ${null} + ${undefined} | ${null} + ${'2022-10-15'} | ${0} + ${'2021-10-12'} | ${1} + ${'2021-10-18'} | ${0} `(`dob $dateOfBirth is $currentAge years old today`, ({ dateOfBirth, currentAge }) => { - const now = DateTime.fromISO('2022-10-15') + const now = DateTime.fromISO('2022-10-15', { zone: 'utc' }) expect(dobToAge(dateOfBirth, now)).toBe(currentAge) }) diff --git a/libs/shared/src/utils/date-utils.ts b/libs/shared/src/utils/date-utils.ts index 6aa35d6c..ac87503e 100644 --- a/libs/shared/src/utils/date-utils.ts +++ b/libs/shared/src/utils/date-utils.ts @@ -132,7 +132,7 @@ export function dobToAge(dob: string | Date | DateTime | null | undefined, now = ? DateTime.fromJSDate(dob, { zone: 'utc' }) : dob - return Math.max(Math.floor(now.diff(normalizedDate, 'years').years), 0) + return Math.floor(now.diff(normalizedDate, 'years').years) } // We allow a maximum of 30 years of history for performance reasons (hypertable chunking)