Package Exports
- elapsed
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (elapsed) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Elapsed
npm install elapsedA 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),
numproperty is the time in Number,textis the time in String. - seconds: (Object),
numproperty is the time in Number,textis the time in String. - minutes: (Object),
numproperty is the time in Number,textis the time in String. - hours: (Object),
numproperty is the time in Number,textis the time in String. - days: (Object),
numproperty is the time in Number,textis the time in String. - weeks: (Object),
numproperty is the time in Number,textis the time in String. - months: (Object),
numproperty is the time in Number,textis the time in String. - years: (Object),
numproperty is the time in Number,textis 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
todate.tois 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);