diff --git a/packages/predate-website/docs/api/isDateTimeEqual.md b/packages/predate-website/docs/api/isDateTimeEqual.md new file mode 100644 index 0000000..bd652c4 --- /dev/null +++ b/packages/predate-website/docs/api/isDateTimeEqual.md @@ -0,0 +1,10 @@ +# `isDateTimeEqual` + +The `isDateTimeEqual` function checks if day, month, year, hours, minutes, seconds and milliseconds are equal. + +```ts +function isDateTimeEqual( + first: PreDateTime, + second: PreDateTime +): boolean; +``` diff --git a/packages/predate/src/isDateTimeEqual.test.ts b/packages/predate/src/isDateTimeEqual.test.ts new file mode 100644 index 0000000..8cd9fe7 --- /dev/null +++ b/packages/predate/src/isDateTimeEqual.test.ts @@ -0,0 +1,25 @@ +/* eslint-disable functional/functional-parameters */ +/* eslint-disable functional/no-return-void */ +/* eslint-disable functional/no-expression-statement */ +import { createDateTime } from "./createDateTime"; +import { isDateTimeEqual } from "./isDateTimeEqual"; + +describe("isDateTimeEqual", () => { + it("should return \"true\" when two equal \"PreDateTime\" are given", () => { + const firstDate = createDateTime.fromArray([2022, 0, 1, 12, 15, 30, 60]); + const secondDate = createDateTime.fromArray([2022, 0, 1, 12, 15, 30, 60]); + + const actualIsEqual = isDateTimeEqual(firstDate, secondDate); + + expect(actualIsEqual).toBe(true); + }); + + it("should return \"false\" when two unequal \"PreDateTime\" are given", () => { + const firstDate = createDateTime.fromArray([2022, 0, 1, 12, 15, 30, 60]); + const secondDate = createDateTime.fromArray([2022, 1, 1, 12, 15, 30, 60]); + + const actualIsEqual = isDateTimeEqual(firstDate, secondDate); + + expect(actualIsEqual).toBe(false); + }); +}); diff --git a/packages/predate/src/isDateTimeEqual.ts b/packages/predate/src/isDateTimeEqual.ts new file mode 100644 index 0000000..a81d9d1 --- /dev/null +++ b/packages/predate/src/isDateTimeEqual.ts @@ -0,0 +1,22 @@ +import { PreDateTime } from "./types"; + +/** + * Checks if day, month, year, hours, minutes, seconds and milliseconds are equal. + * @param first + * @param second + * @returns + */ +export const isDateTimeEqual = ( + first: PreDateTime, + second: PreDateTime +): boolean => { + return ( + first.day === second.day && + first.month === second.month && + first.year === second.year && + first.hours === second.hours && + first.minutes === second.minutes && + first.seconds === second.seconds && + first.milliseconds === second.milliseconds + ); +};