Skip to content

Commit

Permalink
feat: add isDateTimeEqual function (#79)
Browse files Browse the repository at this point in the history
* feat: add `isDateTimeEqual` function

#78

* test: add tests for `isDateTimeEqual`

#78

* docs: add docs for `isDateTimeEqual`

#78
  • Loading branch information
Bikossor authored Jun 12, 2022
1 parent b9adc3c commit 6387b0f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/predate-website/docs/api/isDateTimeEqual.md
Original file line number Diff line number Diff line change
@@ -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;
```
25 changes: 25 additions & 0 deletions packages/predate/src/isDateTimeEqual.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
22 changes: 22 additions & 0 deletions packages/predate/src/isDateTimeEqual.ts
Original file line number Diff line number Diff line change
@@ -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
);
};

0 comments on commit 6387b0f

Please sign in to comment.