Not Particularly Meaningful
Publish your own packages to the world's most popular software ecosystem with npm Pro.Get started »

epoch-to-timeago

1.0.1 • Public • Published

epoch-to-timeago npm version Build Status

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

Install

npm i epoch-to-timeago

DownloadsWeekly Downloads

19

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar