Skip to content

Commit

Permalink
determind the dates in test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
samaradel committed Sep 19, 2024
1 parent 6d779af commit c07a53b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions packages/playground/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 9 additions & 7 deletions packages/playground/tests/utils/isReleasedOverMon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit c07a53b

Please sign in to comment.