0.0.5 • Published 10 months ago

date-handle v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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); // prints the new date with 5 days, 2 months, and 1 year added

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); // add 7 days to end date
const difference = dateHandle.difference(startDate, endDate);
console.log(difference); // prints the difference in time between the two dates

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); // prints the date that is 5 days in the future

const pastDate = DateHandle.past(2, 'months');
console.log(pastDate); // prints the date that is 2 months in the past

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()); // prints true or false
0.0.5

10 months ago

0.0.4

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

3 years ago