:package: date-handle
Handle with dates on JS and TS
Report Bug
Request Feature
Did you like the project? Please, considerate a donation to help improve!
Handle with dates on JS and TS✨
Getting started
Installation
With NPM
npm i date-handle
Usage
Import the library
To start using the library, you will need to import it first.
import { DateHandle } from 'date-handle';
You can then create a new instance of the DateHandle class:
const dateHandle = new DateHandle();
With the dateHandle
instance, you can access the different methods provided by the library. For example, you can use the add
method to add a certain number of days, months, or years to a given date:
const newDate = dateHandle.add(new Date(), { days: 5, months: 2, years: 1 });
console.log(newDate);
You can also use the difference
method to calculate the difference between two dates:
const startDate = new Date();
const endDate = new Date();
endDate.setDate(endDate.getDate() + 7);
const difference = dateHandle.difference(startDate, endDate);
console.log(difference);
Get future and past dates
You can get future and past dates. The future and past methods receive two parameters, the first one is the number of days, months or years you want to add/subtract and the second one is the type of time ('days', 'months' or 'years').
const futureDate = DateHandle.future(5, 'days');
console.log(futureDate);
const pastDate = DateHandle.past(2, 'months');
console.log(pastDate);
Check if it's a specific day of the week
You can check if it's a specific day of the week. The dayOfWeek, isSaturday, isSunday and isMonday methods receive one parameter, the day of the week you want to check (0 for Sunday, 1 for Monday, 6 for Saturday).
console.log(dateHandle.isMonday());