JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3603
  • Score
    100M100P100Q129395F

A date formatter and parser for node

Package Exports

  • dateable

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dateable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

build status

dateable

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

Install

$ npm install dateable

Use

var dateable = require('dateable');

var str = dateable(new Date(), 'MM/DD-YYYY, hh:mm');  // => 03/23-2012, 22:10
dateable.parse(str, 'MM/DD-YYYY, hh:mm')              // Returns the original date

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

var date = new Date(2009, 4, 23);
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.

var date = new Date(2008, 4, 20);

dateable.when(date);                        // => 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

dateable#parse(date, format)

Return original date from format

dateable#when(date, [unit])

Returns relative date in specified or closest matching unit

dateable#language(language)

Set language

Why?

Because dealing with dates in javascript is a fucking pain in the ass!