Elapsed
npm install elapsed
A module for getting the elapsed time between two dates in various representation.
var Elapsed = ;var elapsedTime = 2013 05 2 2013 05 25;console; // 33120console; // "552 hours"console; // "3 weeks"
create
var elapsedTime = 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 = 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 = from i10n;