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

javascript-timeframe

v1.1.0

Published

Localize date formatting, both in the past and present in human readable format, i.e 2 minutes ago, in 5 years etc.

Downloads

2

Readme

Javascript-timeframe

Localize date formatting, both past and present in human readable format

It format date in readable format

Example:

  • 1 minute ago
  • 2 months ago
  • in 3 months
  • just now
  • 4 years ago

Install

Option A. NPM install

npm install javascript-timeframe --save

Option B. Use CDN

You can load timeline directly from jsDelivr CDN.

https://cdn.jsdelivr.net/gh/johnerry/javascript-timeframe/src/timeframe.js

For example, place this in your HTML:

<script src="https://cdn.jsdelivr.net/gh/johnerry/javascript-timeframe/src/timeframe.js"></script>

Option C. Use CDN

Copy the timeframe.js file containing only few lines of code to your project, and load it.

<script src="timeframe.js"></script>

Use

import {timeFrame} from 'javascript-timeframe'

const date = new timeFrame('2020-05-17T03:24:00');
//const date = new timeFrame(1589682240); unix

date.startingDate('2020-01-10T04:04:05');

// date.language('es');  spanish

date.language('en');  // english

console.log( date.moment() );
//  in 4 months

console.log( date.unix() );
//  1589682240

new timeFrame()  accepts all argument that a regular Date method can, including unix time digit.

if you do not specify a startingDate, timeFrame automatically uses the current time for comparison.

Other functionality

const date = new timeFrame('2020-05-17T23:24:00');
  
  console.log( date.now() );
  // returns the current milliseconds rather that the argument passed into timeFrame
  //  1611501800638
  
  console.log( date.unix() );
  // 1589754240
  // returns unix time interger of passed argument since january 1st 1970
  
  console.log( date.milliseconds() );
  // 0
  // returns milliseconds of passed argument

 console.log( date.seconds() );
 // 0
 // returns seconds in passed argument
 
 console.log( date.minutes() );
 // 24
 //returns minutes in passed argument
 
 console.log ( date.hours().long(), date.hours().short() );
 // 23, 11
 //returns hours in passed argument
 
 console.log( date.day() );
 // 17
 //return the day in passed argument
 
 console.log( date.month() );
 // May
  //return the month in the passed argument
 
 console.log( date.year() );
 // 2020
  //return the year in passed argument

Locales

Library lets you format date and time in your local language.

If no argument is matched, the "default language" is used, and the default language is "en" by default.

const date = new timeFrame('2020-05-17T03:24:00');

date.language('en'); // English
  
date.language('ru'); // Russian

date.language('es');  // Spanish

date.language('de');  // German

date.language('th');  // Thai

  // search for your language short code and pass it in. The last language code passed will be used.

Future

When future date are provided, moment()  return results like:

const date = new timeFrame('2021-05-17T03:24:00');
  console.log( date.moment() );
  //  in 3 months

License

MIT