From c07a53bf4d1c29efb2d95e2826d0e6e4be453ec3 Mon Sep 17 00:00:00 2001 From: samaradel Date: Thu, 19 Sep 2024 18:23:12 +0300 Subject: [PATCH] determind the dates in test cases --- packages/playground/src/utils/date.ts | 12 ++++++------ .../tests/utils/isReleasedOverMon.test.ts | 16 +++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/playground/src/utils/date.ts b/packages/playground/src/utils/date.ts index ac5bafdd04..3732b29f14 100644 --- a/packages/playground/src/utils/date.ts +++ b/packages/playground/src/utils/date.ts @@ -5,15 +5,15 @@ export default function toHumanDate(timeInSeconds: number): string { } /** - * Checks if a release date is within the last 30 days from a given current date. + * Checks if a release date is within the last 30 days from the current date. * - * @param {Date} releaseDate - The date of release. - * @param {Date} [currentDate] - The current date to compare with. Defaults to the current date. - * @returns {boolean} True if the release date is within the last 30 days, false otherwise. + * @param {Date} releaseDate - The date of release + * @param {Date} currentDate - The current date + * @returns {boolean} True if the release date is within the last 30 days, false otherwise */ export function isReleasedOverMon(releaseDate: Date, currentDate: Date): boolean { - const thirtyDaysInMilliseconds = 24 * 60 * 60 * 1000; - const diff = Math.abs((currentDate.getTime() - releaseDate.getTime()) / thirtyDaysInMilliseconds); + const millisecondsInADay = 24 * 60 * 60 * 1000; + const diff = Math.abs((currentDate.getTime() - releaseDate.getTime()) / millisecondsInADay); return diff <= 30; } diff --git a/packages/playground/tests/utils/isReleasedOverMon.test.ts b/packages/playground/tests/utils/isReleasedOverMon.test.ts index 9efbfed725..4617f24f3b 100644 --- a/packages/playground/tests/utils/isReleasedOverMon.test.ts +++ b/packages/playground/tests/utils/isReleasedOverMon.test.ts @@ -4,18 +4,20 @@ import { isReleasedOverMon } from "../../src/utils/date"; describe("isReleasedOverMon", () => { it("return true if the releaseDate is within 30 days", () => { - const releaseDate = new Date(Date.now() - 20 * 24 * 60 * 60 * 1000); - expect(isReleasedOverMon(releaseDate, new Date())).toBe(true); + const releaseDate = new Date("2024-09-1"); + const currentDate = new Date("2024-09-19"); + expect(isReleasedOverMon(releaseDate, currentDate)).toBe(true); }); it("return false if the releaseDate was from more than 30 days", () => { - const releaseDate = new Date(Date.now() - 50 * 24 * 60 * 60 * 1000); - - expect(isReleasedOverMon(releaseDate, new Date())).toBe(false); + const releaseDate = new Date("2024-09-1"); + const currentDate = new Date("2024-11-19"); + expect(isReleasedOverMon(releaseDate, currentDate)).toBe(false); }); it("return true if releaseDate is today", () => { - const releaseDate = new Date(); - expect(isReleasedOverMon(releaseDate, new Date())).toBe(true); + const releaseDate = new Date("2024-09-19"); + const currentDate = new Date("2024-09-19"); + expect(isReleasedOverMon(releaseDate, currentDate)).toBe(true); }); });