npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

relative-date-component

0.0.4

@tjholowaychuk

npmSnykSocket
Downloads:18
$ npm install relative-date-component
DailyWeeklyMonthlyYearly

relative-date

Relative dates in words

Installation

$ component install component/relative-date

API

relative(date)

Return the date in words relative to Date.now():

var relative = require('relative-date');
var date = new Date(Date.now() + 2000);

var str = relative(date) + ' ago';
// => "2 seconds ago"

An empty string "" is returned when the difference is below one second. You may use this to default the string as shown here:

var str = relative(new Date) || 'just now';
// => "just now"

var str = relative(new Date);
if (str) str = 'assignment due in ' + str;
else str = 'assignment due';
// => "assignment due"

relative(date, other)

Same as above, relative to other instead of Date.now().

License

MIT