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

date-duration

v2.0.0

Published

Manipulate Date objects with ISO 8601-formatted durations

Downloads

990

Readme

date-duration ci

Manipulate Date objects with ISO 8601-formatted durations.

Installation

$ npm install date-duration

Usage

import Duration from 'date-duration';

let duration = Duration('PT1H');
// or
let duration = Duration({P: {T: {H: 1}}});

Note: keep in mind that working with time-only durations (hours, minutes, seconds) is generally a better idea.

A duration of PT36H is not the same as P1DT12H. The former will add/subtract exactly 36 hours while the latter will add 12 hours + whatever 1 day means. e.g. if jumping across DST (Daylight saving time) and the difference is 1 hour, this totals to plus/minus 35 hours or 37 hours.

This is generally what you want as long as you take into account this happens within the context of the timezone of your environment. This can become tricky when used in browsers (where you don't have control over this).

API

Duration(ISOString)

Pass a string in ISO 8601 duration format to create a duration.

duration.addTo(Date)

Add the duration to a Date object and returns the new date. Objects with a .toDate() (like Moment.js) method are converted to a regular Date object.

duration.subtractFrom(Date)

Subtract the duration from a Date object and returns the new date. Objects with a .toDate() method are converted to a regular Date object.

duration.add(Duration)

Add durations together returning a new duration which is the sum of both.

duration.multiply(number)

Multiply individual parts of duration returning a new duration as the result.

duration.toString()

Convert a duration to a string in ISO 8601 format.