npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-date-utilities

v1.1.1

Published

A module that adds new methods to the native Date class.

Downloads

3

Readme

node-date-utilities

npm version Build Status Coverage Status GitHub repo size

A module that adds new methods to the native Date class.

Installation

npm install node-date-utilities

Usage

In order to use the methods, you only need to import the package and the everything will be available.

require('node-date-utilities');

or

import  'node-date-utilities';

Methods

Static methods

Date.isLeapYear(year: number): Boolean

Checks if a specific year is a leap year

  • year: {number} the year to be checked
Example use
Date.isLeapYear(1996) // true
Date.isLeapYear(1995) // false

Date.getDaysInMonth(year: number, month: number): number

Returns the number of days of a month in a specific year

  • year: {number} the year to be considered
  • month: {number} The month whose days will be counted
Example use
Date.getDaysInMonth(1996, 0) // 31
Date.getDaysInMonth(1996, 1) // 29

Date.tomorrow(): Date

Returns a Date instance of the next day

Example use
const tomorrow = Date.tomorrow() 

Date.yesterday(): Date

Returns a Date instance of the previous day

Example use
const yesterday = Date.yesterday() 

Date.sameDay(date1: Date, date2: Date): boolean

Check if two dates are the same day

  • date1: {Date} the first date
  • date2: {Date} the second date
Example use
const date1 = new Date("1995-02-17T03:24:00");
const date2 = new Date("1995-02-17T12:24:00");

Date.sameDay(date1, date2) // true

Instance methods

add(options: AddSubOptions): Date;

Adds a specific number of days/months/years to the current Date instance

  • options: AddSubOptions values to be added/subtracted
{
    years: 1,
    months: 1,
    days: 1
}
Example use
const date = new Date("1995-02-17T03:24:00");

date.add({days: 1}); // 1995-02-18T03:24:00
date.add({months: 1}); // 1995-03-18T03:24:00

date.add({years: 1}); // 1996-01-18T03:24:00

subtract(options: AddSubOptions): Date;

Subtracts a specific number of days/months/years to the current Date instance

  • options: AddSubOptions values to be added/subtracted
{
    years: 1,
    months: 1,
    days: 1
}
Example use
const date = new Date("1995-02-17T03:24:00");

date.subtract({days: -1}); // 1995-02-16T03:24:00
date.subtract({months: -1}); // 1995-01-18T03:24:00

date.add({years: -1}); // 1994-01-18T03:24:00

isLeapYear(): Boolean

Checks if the current Date instance is a leap year

Example use
const date = new Date("1995-02-17T03:24:00");

date.isLeapYear(); // false

clearTime(): Date

Removes the time part from a Date instance

Example use
const date = new Date("1995-02-17T03:24:00");

date.clearTime(); // 1995-02-17T00:00:00.0000

getDaysInMonth(): number

Returns the number of days of the instance month

Example use
const date = new Date("1995-01-17T03:24:00");

date.getDaysInMonth(); // 31

clone(): Date

Clones the current Date instance

Example use
const date = new Date("1995-01-17T03:24:00");

const clone = date.clone();

Test

npm run test