Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

ago

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ago

A tool for calculating relative timestamps to now.

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
111
29.07%
Maintainers
1
Weekly downloads
 
Created
Source

ago

NPM

ago is a simple function for calculating a timestamp some amount of time ago. (or in the future)

var ago = require("ago")

ago(344) // 344 milliseconds ago, e.g. 1376505400233
ago(344, "ms") // same as above, default unit is "ms"
ago(4, "minutes") // four minutes ago
ago(3, "days") // 3 * 24 hours ago
ago(1, "quarter") // one quarter (13 weeks) ago

ago(2, "months") // months are approximate (30.4375 days)
ago(22, "y") // years are approximate as well (365.25 days)

console.log(new Date(ago(35.3086, "y")))
// Mon Apr 24 1978 00:06:49 GMT-0800 (PDT)

// It also exposes a fromNow() function to calculate future times. e.g:
ago.fromNow(1, "year")
// is just sugar for:
ago(-1, "year")


API

ago(number [,unit])

Calculate a millisecond epoch timestamp relative to right now.

  • number: a number (e.g. 1, 20, 0.25)
  • unit: a time unit. Defaults to milliseconds
    • ms, millis, millisecond, milliseconds
    • s, sec, secs, second, seconds
    • m, min, mins, minute, minutes
    • h hr, hrs, hour, hours
    • d, day, days
    • w, wk, wks, week, weeks
    • M, mon, mons, month, months (30.4375 days)
    • q, qtr, qtrs, quarter, quarters
    • y, yr, yrs, year, years (365.25 days)

ago.fromNow(number [,unit])

This is a convenience function for ago(-number, [,unit]) for finding timestamps in the future.

LICENSE

MIT

Keywords

date

FAQs

Package last updated on 14 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts