npm

Join us for the upcoming webinar, "Enterprise JavaScript done right: the tools you love, the security you need."Sign up here »

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

11

version

1.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability