You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

datum.js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datum.js

Utility function for diplaying time in a readable way

0.7.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

datum.js

datum.js is a javascript utility that makes it easy to print readable dates, e.g. 4 minutes ago.

Install the package from npm

npm install --save datum.js

Usage

Just pass a Date object to the function and datum.js will convert it to a readable string.

Datum.js supports the following epochs

  • year
  • month
  • day
  • hour
  • minute
import datum from 'datum.js';

// Create a new date that reflects 2 minutes ago
const oneMinutesAgo = new Date().setMinutes(new Date().getMinutes() - 1);
// Create a new date that reflects 5 days ago
const oneDaysAgo = new Date().setDate(new Date().getDate() - 1);

datum(oneMinutesAgo); // => '1 minute ago'
datum(oneDaysAgo); // => '1 day ago'

If the returned value is greater then one, we will add a suffix to the epoch

import datum from 'datum.js';

// Create a new date that reflects 2 minutes ago
const twoMinutesAgo = new Date().setMinutes(new Date().getMinutes() - 2);
// Create a new date that reflects 5 days ago
const twoDaysAgo = new Date().setDate(new Date().getDate() - 2);

datum(twoMinutesAgo); // => '2 minutes ago'
datum(twoDaysAgo); // => '2 days ago'

API

datum(date, [options])

The parse method takes a Date object and returns a string

date

The date param always need to be a date object and will always return a string.

Options

datum.js allows you to change the exception value, i.e the value that will be displayed when the date is less than 1 minute to anything you want.

var options = {
    exception: '0 minutes a go',
};

License

MIT. Copyright (c) 2017 Philip Knape.

FAQs

Package last updated on 20 Jan 2017

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