⏱ A tiny set of utilities to compare JS dates.
npm install @ericadamski/quicktime⏱ A tiny set of utilities to compare JS dates.
```
yarn add @ericadamski/quicktime
or
``
npm i @ericadamski/quicktime
Each function takes two JS Dates and a third possible parameter that specifies the granularity of the comparison. All of the following examples compare the entire date down to the milliseconds.
Check if a give time is after another time.
`javascript
import { isAfter } from "@ericadamski/quicktime";
isAfter(new Date("10/10/2010"), new Date()); // false
`
Check if a give time is before another time.
`javascript
import { isBefore } from "@ericadamski/quicktime";
isBefore(new Date("10/10/2010"), new Date()); // true
`
Check if a give time is before another time.
`javascript
import { isEqual } from "@ericadamski/quicktime";
isEqual(new Date("10/10/2010"), new Date()); // false
`
All of the function above can be augmented by passing the part of the date you want to compare. The date will always compare the time segment specified and any segment larger. For example if you compare using days then quicktime will make sure that the day, month and year are the same but will ignore hours, minutes, seconds, and milliseconds.
The available time segments to compare with are:
- milliseconds (default)
- seconds
- minutes
- hours
- days
- months
- years
`javascript
import { isAfter } from "@ericadamski/quicktime";
isAfter(new Date("10/10/2010"), new Date("11/10/2010"), "days"); // false
`
Check if a give time is before another time.
`javascript
import { isBefore } from "@ericadamski/quicktime";
isBefore(new Date("10/10/2010"), new Date("11/10/2010"), "days"); // true
`
Check if a give time is before another time.
`javascript
import { isEqual } from "@ericadamski/quicktime";
isEqual(new Date("10/10/2010"), new Date("10/10/2010"), "days"); // true
isEqual(new Date("10/10/2010"), new Date("10/10/2011"), "days"); // false
``