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

@korbiniankuhn/datetime

v1.1.3

Published

High performance date manipulations

Downloads

24

Readme

datetime

Travis Coverage Known Vulnerabilities Dependencies Dev Dependencies npm npm-version code style: prettier license

High performance date manipulations.

This library just provides human readable functions for simple, mostly mathematical date operations. All operations are expecting a valid date object and do not check their input arguments to provide maximum performance. If you want immutability, use the clone function.

There are already a lot of very good libraries like momentjs, date-fns, dayjs or instadate.

Use this library, if you want:

  • the highest performance
  • have a moment like syntax

Don't use this library, if you need:

  • language internationalization
  • date input or output parsing support for various non-standard formats

All functions are tested against momentjs operations.

Installation

For installation use the Node Package Manager:

$ npm install --save @korbiniankuhn/datetime

or clone the repository:

$ git clone https://github.com/KorbinianKuhn/datetime

Getting started

const datetime = require('@korbiniankuhn/datetime');

/* Create new date object add two months and return native date object */
datetime()
  .add(2, 'months')
  .toDate();

/* An immutable usage */
datetime()
  .clone()
  .subtract(1, 'year')
  .toDate();

/* Create a new utc date */
datetime
  .utc()
  .add(2000, 'ms')
  .toDate();

/* Use existing date */
datetime(new Date())
  .startOf('month')
  .toDate();

API

datetime().add(amount, unit): Add interval to date.

datetime().clone(): Create a copy of the date.

datetime().daysInMonth(): Get the number of days in month.

datetime().daysInQuarter(): Get the number of days in quarter.

datetime().daysInYear(): Get the number of days in year.

datetime().diff(date, unit): Get the difference between two dates.

datetime().endOf(unit): Set date to end of given interval.

datetime().getQuarter(): Get quarter of date in year. First quarter starts with 1.

datetime().get(unit): Get value of given unit.

datetime().isAfter(date, unit): Check if date is after another date.

datetime().isBefore(date, unit): Check if date is before another date.

datetime().isLeapYear(): Check if date is a leap year.

datetime().isSame(date, unit): Check if date is same as another date.

datetime().isSameOrAfter(date, unit): Check if date is same as or after another date.

datetime().isSameOrBefore(date, unit): Check if date is same as or after another date.

datetime().isUTC(): Returns if the DateTime object is in UTC mode.

datetime().isValid(): Check if date is valid.

datetime().set(value, unit): Set value of given unit.

datetime().startOf(unit): Set date to end of given interval.

datetime().subtract(amount, unit): Subtract interval from date.

datetime().toUTC(): Convert date to utc timezone.

datetime().unix(): Get a unix timestamp of the date (without milliseconds).

Testing

First you have to install all dependencies:

$ npm install

To execute all unit tests once, use:

$ npm test

To get information about the test coverage, use:

$ npm run test:coverage

Contribution

Get involved and push in your ideas.

Do not forget to add corresponding tests to keep up 100% test coverage.

License

The MIT License