mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 07:25:19 +02:00
normalize all DateTime calls to utc in test
This commit is contained in:
parent
b00f97d033
commit
538583d811
2 changed files with 11 additions and 11 deletions
|
@ -38,14 +38,14 @@ describe('converts between years and ages', () => {
|
||||||
dateOfBirth | currentAge
|
dateOfBirth | currentAge
|
||||||
${'1995-02-20'} | ${27}
|
${'1995-02-20'} | ${27}
|
||||||
${new Date('Feb 20 1995')} | ${27}
|
${new Date('Feb 20 1995')} | ${27}
|
||||||
${DateTime.fromISO('1995-02-20')} | ${27}
|
${DateTime.fromISO('1995-02-20', { zone: 'utc' })} | ${27}
|
||||||
${null} | ${null}
|
${null} | ${null}
|
||||||
${undefined} | ${null}
|
${undefined} | ${null}
|
||||||
${'2022-10-15'} | ${0}
|
${'2022-10-15'} | ${0}
|
||||||
${'2021-10-12'} | ${1}
|
${'2021-10-12'} | ${1}
|
||||||
${'2021-10-18'} | ${0}
|
${'2021-10-18'} | ${0}
|
||||||
`(`dob $dateOfBirth is $currentAge years old today`, ({ dateOfBirth, currentAge }) => {
|
`(`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)
|
expect(dobToAge(dateOfBirth, now)).toBe(currentAge)
|
||||||
})
|
})
|
||||||
|
|
|
@ -132,7 +132,7 @@ export function dobToAge(dob: string | Date | DateTime | null | undefined, now =
|
||||||
? DateTime.fromJSDate(dob, { zone: 'utc' })
|
? DateTime.fromJSDate(dob, { zone: 'utc' })
|
||||||
: dob
|
: 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)
|
// We allow a maximum of 30 years of history for performance reasons (hypertable chunking)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue