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 🙏

© 2026 – Pkg Stats / Ryan Hefner

date-update

v1.1.1

Published

An update for js' Date class

Readme

date-update — an update for js' Date class

Js' Date is a very useful class, but sometimes to doing something "simple" you have to write a lot of boring code (even with other similar libraries).

That's why I've wrote this package that add some methods to Date objects which simplify the usage of them.

This package mainly helps in manage the date "as a value" (mathematical and data stuff) and NOT in formatting or similar.

Any suggestions are welcome, fell free to make a pull request!

Usage

Install it form npm

$ npm install date-update

and import it into your project:

require('date-update');

Added methods

All of these method create a new Date object and don't modify itself

In this extension all time unit of measure have a string that represent itself:

  • Years: y
  • Month: M
  • Days: d
  • Hours: h
  • Minutes: m
  • Seconds: s
  • Milliseconds: ms
  • trim(a, b):
    returns a new date resetting the date/time not in [a; b], where a and b are a time unit.
    For example, if you use it in this way

    var time = new Date("2020-08-16T08:19:46.590Z").trim('h', 'ms')

    you will obtain "1970-01-01T08:19:46.590Z", i.e. resets years, months and days and keep hours, minutes, seconds and milliseconds

    NB: it supports even "circular interval", for example new Date("2020-08-16T08:19:46.590Z").trim('s', 'd') will produce 2020-08-16T00:00:46.590Z, i.e. keep seconds, milliseconds, year, month and day only.

  • add(s):
    add an amount of time (specified by an expression of time unit) to the date.
    The expression must be a sequence of integer and time unit (for example "2M -4h" which add 2 month and subtract 4 hours):

    var date = new Date("2020-08-16T08:19:46.590Z").add("+5M -15d")

    date will be "2021-01-01T08:19:46.590Z"

    NB: it supports even "broken value" (for example "+365d" will add a year, if the actual year is not bissextile) and also repetition of the same time unit (for example "+3h -5h")

  • fixOffset:
    Since this library reason in UTC to avoid some other problems, to get the correct local date you have to adjuts the timezone offset. This function returns a new date with the correct offset.

    For example with a timezone +-x where x!=0:

    new Date('2021/01/01').trim('y','d').getDate() // 31

    because of the "setUTC...", to avoid this problem easily use fixOffset like below:

    new Date('2021/01/01').trim('y','d').fixOffset().getDate() // 1