npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@interwebalex/its-a-date

v1.2.14

Published

A Natural Language Date Description Processor

Downloads

762

Readme

alt tag

When given a Date description, it returns a Date object. No need to know exact date format.

Currently supporting languages:

  • English
  • Russian
  • Arabic
  • Persian
  • Turkish
  • Greek
  • Spanish
  • French

Installation

$ npm install its-a-date --save

Code Example

var itsadate = require('its-a-date');

// Mon May 02 2016 05:48:00 GMT+0300 (Jerusalem Daylight Time)`
itsadate.parse('May 2 05:48:29 2016');

// Wed Apr 11 1990 00:45:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse('3 months after 11/01/1990');

// Sat Aug 26 1989 02:43:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse('10000 days before 11/01/2017');

More Code Examples

Parse Hour & Date

// Fri Aug 19 2016 11:47:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse('11:47');

// Tue Mar 27 2012 14:05:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse('27.3.2012');

// Tue Mar 27 2012 12:00:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse('27/3/2012 12:00');

Parse Relatives

// Thu Aug 18 2016 14:05:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse('yesterday');

// Thu Aug 18 2016 16:20:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse('yesterday at 16:20');

//Fri Aug 19 2011 14:05:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse('5 years ago');

// Fri Aug 19 2011 15:44:00 GMT+0300 (Jerusalem Daylight Time)
itsadate.parse('5 years ago at 15:44');

Parse the Extreme (Not Recommended)

When its-a-date doesn't know what date it is, it will return undefined. However many times it surprises.

// Sun Jan 01 1984 14:05:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse('it was on the 1st of January, ' + 'the dark cold winter of 1984');

// undefined
itsadate.parse('pikachu');

Settings, Formats & Time Differences

Use settings to alter the format expected

// Hint its-a-date to prefer mm/dd/yyyy over dd/mm/yyyy
itsadate.settings({ day_before_month: false });

// Thu Nov 01 1990 01:55:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse('11/1/1990');
// Don't allow its-a-date to guess any other format than specified (day MUST be before month or vise-versa)
itsadate.settings({ strict: true });

You can prevent changing the settings globaly, by delivering it as a second parameter

// November 3rd 2014
itsadate.parse('11-3-2014', { day_before_month: false });

// Doesn't use prev settings March 11th 2014
itsadate.parse('11-3-2014');

Restore settings to default

// Restore setting back to default (day_before_month=true)
itsadate.settings().restore();

// Thu Jan 11 1990 01:55:00 GMT+0200 (Jerusalem Standard Time)
itsadate.parse('11/1/1990');

Alter GMT to overcome time difference

// Set GMT+5.5, Mumbai India
itsadate.settings({ gmt: 5.5 });
itsadate.parse('now');

Change the base date that its-a-date uses to 'fill in' blanks

// Set base date to 31st December 1999
itsadate.settings({ base_date: new Date(1999, 11, 31) });

// Mon May 31 1999 00:00:00 GMT+0100 (British Summer Time)
itsadate.parse('May');

Learn More

Hit brag() to console out examples of any token implemented

itsadate.brag();

Hit settings() to get settings object with configutations you can alter. descriptions included.

itsadate.settings();

No Exceptions

When date description has inner conflicts it resolves to undefined

// undefined
itsadate.parse('1st of november 02/03/2000');

Motivation

  1. Allows a user to type a date more naturally in a web page or social media.
  2. Allows crawlers to parse relative dates easily.

Strategy (How it works?)

A micro-compiler is implemented. It parses date part tokens & interpret them as modifications on the perceived date.

Upcoming Features

  1. Custom token insertion
  2. More Languages perhaps

Git

https://github.com/bendorshai/its-a-date