2023-10-23 23:11:59 +02:00
|
|
|
export const BIRTH_DATE_DAY = "31" as const
|
|
|
|
export const BIRTH_DATE_MONTH = "03" as const
|
|
|
|
export const BIRTH_DATE_YEAR = "2003" as const
|
2023-05-30 21:51:27 +02:00
|
|
|
export const BIRTH_DATE_STRING =
|
|
|
|
`${BIRTH_DATE_DAY}/${BIRTH_DATE_MONTH}/${BIRTH_DATE_YEAR}` as const
|
|
|
|
export const BIRTH_DATE_ISO_8601 =
|
|
|
|
`${BIRTH_DATE_YEAR}-${BIRTH_DATE_MONTH}-${BIRTH_DATE_DAY}` as const
|
|
|
|
export const BIRTH_DATE = new Date(BIRTH_DATE_ISO_8601)
|
2021-12-04 15:52:51 +01:00
|
|
|
|
|
|
|
/**
|
2023-08-01 14:11:46 +02:00
|
|
|
* Calculates the age of a person based on their birth date.
|
2021-12-04 15:52:51 +01:00
|
|
|
* @param birthDate
|
|
|
|
*/
|
|
|
|
export const getAge = (birthDate: Date): number => {
|
|
|
|
const today = new Date()
|
|
|
|
let age = today.getFullYear() - birthDate.getFullYear()
|
|
|
|
const month = today.getMonth() - birthDate.getMonth()
|
|
|
|
if (month < 0 || (month === 0 && today.getDate() < birthDate.getDate())) {
|
|
|
|
age--
|
|
|
|
}
|
|
|
|
return age
|
|
|
|
}
|