
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
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
Just pass a Date object to the function and datum.js will convert it to a readable string.
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'
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.
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',
};
MIT. Copyright (c) 2017 Philip Knape.
FAQs
Utility function for diplaying time in a readable way
We found that datum.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.