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

Readme

Keywords

Package Sidebar

Install

npm i epoch-to-timeago

Weekly Downloads

5

Version

1.0.1

License

MIT

Last publish

Collaborators

  • chinedufn