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

react-duration-counter

v1.2.6

Published

This is the duration counter for counting elapsed time in human readable format , we can use it in blog or webinar website to show published period or elapsed time

Downloads

23

Readme

react-duration-counter

This is a duration counter for counting elapsed time in human readable format , we can use it in blog or webinar website to show published period or elapsed time

Here is the first example for function humanDate() formatting:

The humanTime function is a utility that takes a timestamp and returns the time elapsed between the timestamp and the current time in a human-readable format. This function can be useful for displaying the time elapsed since a certain event, such as a post publication or a user registration.

 const {humanTime, relativeDate } = require('react-duration-counter')

// INPUT YOUR TIME HERE IN ANY FORMAT 
const published_at = 1680862065904;
 // or any other valid timestamp format
try {
  

  console.log(published_at);
  
  // EXAMPLE INTERVAL I HAVE GIVE NFOR SIMULATION
  setInterval(() => {
   
   // TIMER FUNCTION IS OUR REACT-DURATION-COUNTER
    const timeString = humanTime(published_at);
    console.log(timeString);

  }, 1000); // " 1 second or 2 seconds", "1 minute or 2 minutes", "1 hour or 2 hours", "1 day or 2 days ", etc.

} catch (error) {

  console.error(error.message);
}

Here is the second function for relativeDate formatting:

"relativeDate" is a lightweight and efficient JavaScript function that allows you to format a given date into a human-readable string that describes its relationship to the current date. It provides simple and customizable output options such as "Today," "Yesterday," "Last Weekday," "Month and Date," or "Year, Month, and Date" depending on the time elapsed between the two dates. This function uses the popular "moment.js" library to ensure accurate and consistent date parsing and formatting.

 const {humanTime, relativeDate } = require('react-duration-counter')

// INPUT YOUR TIME HERE IN ANY FORMAT 
const published_at = 1680862065904;
 // or any other valid timestamp format
try {
  

console.log(relativeDate('2023-04-08')); // "Today"
console.log(relativeDate('2023-04-07')); // "Yesterday"
console.log(relativeDate('2023-04-06')); // "Wednesday"
console.log(relativeDate('2023-04-01')); // "Last Saturday"
console.log(relativeDate('2022-10-08')); // "October 8"
console.log(relativeDate('2022-04-08')); // "April 8"
console.log(relativeDate('2021-04-08')); // "Apr 8, 2021"
console.log(relativeDate('invalid-date')); // Error: Invalid published date
console.log(relativeDate(null)); // Error: Published date is required
console.log(relativeDate()); // Error: Published date is required

} catch (error) {

  console.error(error.message);
}

Here is the third function for FutureDateCounter formatting:

The FutureDateCounter function is useful for calculating the duration between the current date/time and a future date/time in a human-readable format. It can be used in various applications, such as countdown timers, project management tools, and scheduling applications. The optional start date parameter allows for flexibility in the calculation, allowing the user to specify a reference date other than the current date/time.


const {humanTime, relativeDate ,FutureDateCounter} = require('react-duration-counter')

try {

// ALWAYS GIVE FUTURE DATE HERE NOT PAST DATE
console.log(FutureDateCounter('2024-06-01'));
// Output: "1 year 1 month"

console.log(FutureDateCounter('2022-08-15'));
// Output: "128 days"

console.log(FutureDateCounter('2024-06-01'));
// Output: "1 year 1 month"

console.log(FutureDateCounter('2023-10-31'));
// Output: "6 months"

// OPtional param start_date it can be past date or can be any date other then same date
console.log(FutureDateCounter('2023-05-01', {start_date: '2022-12-01'}));
// Output: "4 months"

} catch (error) {

  console.error(error.message);
}