epoch-to-timeago
v1.0.1
Published
Get a string representation of a time difference
Downloads
22
Readme
epoch-to-timeago
Get a string representation of a time difference
To Install
$ npm install --save epoch-to-timeago
Usage
var timeAgo = require('epoch-to-timeago').timeAgo
var originalTime = new Date().getTime()
var oneSecond = originalTime + 1000
var twoMinutes = originalTime + (2000 * 60)
timeAgo(originalTime, oneSecond) // 1 second ago
timeAgo(originalTime, twoMinutes) // 2 minutes ago
Cutoffs
Don't like the default cutoffs? Replace them with your own!
var convert = require('epoch-to-timeago')
convert.cutoff.seconds = 63
timeAgo(originalTime, sixtyOneSeconds) // 61 seconds ago
timeAgo(originalTime, sixtyFourSeconds) // 1 minute ago
Suffixes
Don't like the default suffixes? Replace them with your own!
var convert = require('epoch-to-timeago')
convert.suffixDictionary = require('./german-suffix')
var timeAgo = convert.timeAgo
timeAgo(originalTime, oneSecond) // 1 zweite vor
timeAgo(originalTime, twoSeconds) // 2 vor sekundan
Time Calculations
Don't like the default time calculations? Replace them with your own!
var convert = require('epoch-to-timeago')
convert.timeCalcs.months = function (pastEpoch, currentEpoch) {
// 30 day month instead of 31
return (currentEpoch - pastEpoch) / 1000 / 60 / 60 / 24 / 30
}
var timeAgo = convert.timeAgo
License
MIT