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

timediff-word

v1.0.0

Published

timediff-word calculates the time difference between two timestamps and returns a human-readable string representation of the difference in years, days, hours, minutes, and seconds. It's suitable for use in applications that require displaying elapsed tim

Downloads

1

Readme

timediff-word

timediff-word is a JavaScript utility that calculates the time difference between two timestamps and returns a human-readable string representation of the difference in years, days, hours, minutes, and seconds.

Installation

You can install timediff-word via npm:

npm install timediff-word

Usage

To use timediff-word, you need to pass two timestamps as arguments to the function:

const timediff = require('timediff-word');

const timestamp1 = new Date('2022-01-01T00:00:00Z').getTime();
const timestamp2 = new Date().getTime();

const diff = timediff(timestamp1, timestamp2);

console.log(diff); // "1 year and 76 days"

The function will return a string representation of the time difference, using the two largest units of time.

If the time difference is less than one year, the function will only display days, hours, minutes, and seconds.

Examples Here are a few more examples of how to use timediff-word:

const timediff = require('timediff-word');

const timestamp1 = new Date('2022-01-01T00:00:00Z').getTime();
const timestamp2 = new Date().getTime();

const diff1 = timediff(timestamp1, timestamp2);

console.log(diff1); // "1 year and 76 days"

const timestamp3 = new Date('2023-03-17T12:00:00Z').getTime();
const timestamp4 = new Date('2023-03-17T12:30:00Z').getTime();

const diff2 = timediff(timestamp3, timestamp4);

console.log(diff2); // "30 minutes"

const timestamp5 = new Date('2023-03-17T12:00:00Z').getTime();
const timestamp6 = new Date('2023-03-18T12:00:00Z').getTime();

const diff3 = timediff(timestamp5, timestamp6);

console.log(diff3); // "1 day"

const timestamp7 = new Date('2020-01-01T00:00:00Z').getTime();
const timestamp8 = new Date().getTime();

const diff4 = timediff(timestamp7, timestamp8);

console.log(diff4); // "2 years and 76 days"

These examples show how to use timediff-word to calculate the time difference between two timestamps in a variety of scenarios, including differences in years, days, hours, and minutes.

Units

The function returns the two largest units of time in the time difference. The available units and their conversions are:

  • Year: 31536000 seconds
  • Day: 86400 seconds
  • Hour: 3600 seconds
  • Minute: 60 seconds
  • Second: 1 second

License

timediff-word is released under the MIT License. See LICENSE for details.

Contributing

If you find a bug or have a feature request, please open an issue on the GitHub repository.

Pull requests are also welcome!

Credits

timediff-word was created by Pritam Kumar.

GitHub Repository

The source code for timediff-word can be found at https://github.com/developer-pritam/timediff-word.