diff options
Diffstat (limited to 'src/lib/strings/time.ts')
-rw-r--r-- | src/lib/strings/time.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index 6cd70498e..588b84459 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -39,3 +39,13 @@ export function niceDate(date: number | string | Date) { minute: '2-digit', })}` } + +export function getAge(birthDate: Date): number { + var today = new Date() + var age = today.getFullYear() - birthDate.getFullYear() + var m = today.getMonth() - birthDate.getMonth() + if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { + age-- + } + return age +} |