From 5e0c953b1dedb907b4b4a8415a2cfa5bed7aa4bc Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Tue, 14 Mar 2023 12:12:46 +0100 Subject: [PATCH] add minutes to the time until.. --- src/services/time-until.test.ts | 8 ++++++-- src/services/time-until.ts | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/services/time-until.test.ts b/src/services/time-until.test.ts index 2e58a03..cb9958b 100644 --- a/src/services/time-until.test.ts +++ b/src/services/time-until.test.ts @@ -6,6 +6,7 @@ const noTime = () => ({ hours: 0, months: 0, seconds: 0, + minutes: 0, years: 0, }) @@ -27,6 +28,7 @@ describe("time until", () => { months: 0, days: 0, hours: 0, + minutes: 0, seconds: 0, }) }) @@ -36,11 +38,12 @@ describe("time until", () => { vi.setSystemTime(fakeNow) expect(timeUntil("2024-02-12T19:34:22.200Z")).toStrictEqual({ + years: 0, + months: 10, days: 30, hours: 10, - months: 10, + minutes: 9, seconds: 2062, - years: 0, }) }) @@ -61,6 +64,7 @@ describe("has passed", () => { months: 0, days: 0, hours: 0, + minutes: 0, seconds: 1, }) ).toBeFalsy() diff --git a/src/services/time-until.ts b/src/services/time-until.ts index 0b4bc84..b8fbaaf 100644 --- a/src/services/time-until.ts +++ b/src/services/time-until.ts @@ -5,6 +5,7 @@ export interface TimeUntilReturn { months: number days: number hours: number + minutes: number seconds: number } @@ -18,12 +19,13 @@ export const timeUntil = (target: string): TimeUntilReturn => { months: 0, days: 0, hours: 0, + minutes: 0, seconds: 0, } } const interval = dateTimeTarget - .diff(now, ["years", "months", "days", "hours", "seconds"]) + .diff(now, ["years", "months", "days", "hours", "minutes", "seconds"]) .toObject() return { @@ -31,6 +33,7 @@ export const timeUntil = (target: string): TimeUntilReturn => { months: interval.months ? Math.round(interval.months) : 0, days: interval.days ? Math.round(interval.days) : 0, hours: interval.hours ? Math.round(interval.hours) : 0, + minutes: interval.minutes ? Math.round(interval.minutes) : 0, seconds: interval.seconds ? Math.round(interval.seconds) : 0, } }