about summary refs log tree commit diff
path: root/src/lib/strings/time.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/strings/time.ts')
-rw-r--r--src/lib/strings/time.ts10
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
+}