Socket
Book a DemoInstallSign in
Socket

relative-date-component

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relative-date-component

Relative date in words

latest
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

relative-date

Relative dates in words

Installation

$ component install component/relative-date

Example

var date = new Date(Date.now() - 60000);
console.log(relative(date) + ' ago');
// => "one minute ago"

var date = new Date(Date.now() + 5 * 60000);
console.log(relative(date) + ' from now');
// => "5 minutes from now"

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

Keywords

date

FAQs

Package last updated on 26 Sep 2012

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