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.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts
index e505b7892..3823af188 100644
--- a/src/lib/strings/time.ts
+++ b/src/lib/strings/time.ts
@@ -20,6 +20,17 @@ export function getAge(birthDate: Date): number {
 }
 
 /**
+ * Get a Date object that is N years ago from now
+ * @param years number of years
+ * @returns Date object
+ */
+export function getDateAgo(years: number): Date {
+  const date = new Date()
+  date.setFullYear(date.getFullYear() - years)
+  return date
+}
+
+/**
  * Compares two dates by year, month, and day only
  */
 export function simpleAreDatesEqual(a: Date, b: Date): boolean {