add minutes to the time until..

This commit is contained in:
Julien Calixte
2023-03-14 12:12:46 +01:00
parent 2ee8a0de47
commit 5e0c953b1d
2 changed files with 10 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ const noTime = () => ({
hours: 0, hours: 0,
months: 0, months: 0,
seconds: 0, seconds: 0,
minutes: 0,
years: 0, years: 0,
}) })
@@ -27,6 +28,7 @@ describe("time until", () => {
months: 0, months: 0,
days: 0, days: 0,
hours: 0, hours: 0,
minutes: 0,
seconds: 0, seconds: 0,
}) })
}) })
@@ -36,11 +38,12 @@ describe("time until", () => {
vi.setSystemTime(fakeNow) vi.setSystemTime(fakeNow)
expect(timeUntil("2024-02-12T19:34:22.200Z")).toStrictEqual({ expect(timeUntil("2024-02-12T19:34:22.200Z")).toStrictEqual({
years: 0,
months: 10,
days: 30, days: 30,
hours: 10, hours: 10,
months: 10, minutes: 9,
seconds: 2062, seconds: 2062,
years: 0,
}) })
}) })
@@ -61,6 +64,7 @@ describe("has passed", () => {
months: 0, months: 0,
days: 0, days: 0,
hours: 0, hours: 0,
minutes: 0,
seconds: 1, seconds: 1,
}) })
).toBeFalsy() ).toBeFalsy()

View File

@@ -5,6 +5,7 @@ export interface TimeUntilReturn {
months: number months: number
days: number days: number
hours: number hours: number
minutes: number
seconds: number seconds: number
} }
@@ -18,12 +19,13 @@ export const timeUntil = (target: string): TimeUntilReturn => {
months: 0, months: 0,
days: 0, days: 0,
hours: 0, hours: 0,
minutes: 0,
seconds: 0, seconds: 0,
} }
} }
const interval = dateTimeTarget const interval = dateTimeTarget
.diff(now, ["years", "months", "days", "hours", "seconds"]) .diff(now, ["years", "months", "days", "hours", "minutes", "seconds"])
.toObject() .toObject()
return { return {
@@ -31,6 +33,7 @@ export const timeUntil = (target: string): TimeUntilReturn => {
months: interval.months ? Math.round(interval.months) : 0, months: interval.months ? Math.round(interval.months) : 0,
days: interval.days ? Math.round(interval.days) : 0, days: interval.days ? Math.round(interval.days) : 0,
hours: interval.hours ? Math.round(interval.hours) : 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, seconds: interval.seconds ? Math.round(interval.seconds) : 0,
} }
} }