Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dateable

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dateable

A date formatter and parser for node

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
increased by5.1%
Maintainers
1
Weekly downloads
 
Created
Source

dateable

A small library that provides a few very useful methods for displaying dates, including a formatter and a parser.

build status

Install

$ npm install dateable

Use

var dateable = require('dateable');
var date = new Date(2009, 4, 23);

var str = dateable(date, 'MM/DD-YYYY, hh:mm');
// => 05/23-2012, 22:10

Parse a formatted date and return the original Date object

dateable.parse(str, 'MM/DD-YYYY, hh:mm');
// => Sat May 23 2009 00:00:00 GMT+0000 (CEST)

If you want to include text in the formatting, you need to escape it with either ' or ".

var format = '"I went to the moon a" dddd "in" MMMM, YYYY';

dateable(date, format);
// => I went to the moon a Saturday in May, 2009

You can also get the relative date, and the difference between dates.

dateable.when(new Date(2008, 4, 20));
// => 4 years ago
dateable.when(new Date(2020, 4, 30));
// => in 8 years
dateable.diff(new Date(2015), new Date());
// => 3 years

API

dateable(date, format)

Return formatted date

.parse(date, format)

Return original date from format

.when(date, [unit])

Returns relative date

.diff(start, end, [unit])

Returns the difference between the two dates

.language(name)

Set language

Formatting

Based on ISO 8601 with some additions. See tests for examples.

Licence

MIT

Keywords

FAQs

Package last updated on 18 Feb 2014

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc