New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

elapsed

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elapsed

A module for getting the elapsed time between two dates in various representation.

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Elapsed

npm install elapsed

A module for getting the elapsed time between two dates in various representation.

var Elapsed = require('elapsed');

var elapsedTime = new Elapsed(new Date(2013, 05, 2), new Date(2013, 05, 25));

console.log(elapsedTime.minutes.num); // 33120
console.log(elapsedTime.hours.text);  // "552 hours"
console.log(elapsedTime.optimal);     // "3 weeks"
create
var elapsedTime = new Elapsed(from, to, i10n);

The from (required) and to (optional, default: now) must be Date objects. i10n (optional: default: english) must be a plain object.

properties
  • milliSeconds: (Object), num property is the time in Number, text is the time in String.
  • seconds: (Object), num property is the time in Number, text is the time in String.
  • minutes: (Object), num property is the time in Number, text is the time in String.
  • hours: (Object), num property is the time in Number, text is the time in String.
  • days: (Object), num property is the time in Number, text is the time in String.
  • weeks: (Object), num property is the time in Number, text is the time in String.
  • months: (Object), num property is the time in Number, text is the time in String.
  • years: (Object), num property is the time in Number, text is the time in String.
  • optimal: (String), the best from the ones above.
  • from: (Date)
  • to: (Date)
methods
  • set(): calculating the properties.
  • refresh(to): refresh the to date. to is optional it defaults to now.
Localization

If you want to localize the elapsed time, you can provide an object holding the translations by passing it into the constructor as a third argument.

var i10n = {…};
var elapsedTime = new Elapsed(from, to, i10n);

Take a look at the english version, to get an impression of how the object should look like:

var i10n = {
  milliSeconds: ['millisecond', 's'],
	seconds: ['second', 's'],
	minutes: ['minute', 's'],
	hours: ['hour', 's'],
	days: ['day', 's'],
	weeks: ['week', 's'],
	months: ['month', 's'],
	years: ['year', 's']
};

Each property holds an array containing the singular and the plural-suffix.

If you don't need to specify the to-parameter, you can pass in the localization as second parameter:

var i10n = {…};
var elapsedTime = new Elapsed(from, i10n);

Keywords

FAQs

Package last updated on 17 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc