New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dateparser

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dateparser

A human language relative date parser

latest
Source
npmnpm
Version
1.0.6
Version published
Weekly downloads
77
-42.11%
Maintainers
1
Weekly downloads
 
Created
Source

Date Parser

A lightweight JavaScript date library for parsing and formatting natural language relative dates.

An small example set of strings that can be parsed:

two seconds
1 second
every 4 days
every other day
1 hour from now
after 2 hours
once per hour
every 48 hours

Using with Node

Install with npm:

npm install dateparser --save

Using with Browser

Bower

You can use Bower to install.

bower install dateparser
bower install jhaynie/dateparser

JS files

If you don't use Bower as a package manager, you can copy the minified JS from dateparser.min.js to the location of your web assets directory and inclue it in your HTML manually.

API

The API has only 2 methods parse and format.

Parse

To parse a date, call parse with a string of text. The result is an object with two properties: value (Number) and relative (Boolean). The value property is the milliseconds value. The relative property indicates if the value is a relative date or a recurring date.

var result = dateparser.parse('every 1 hour');
console.log('%d', result.value);

If the results relative property is true, the value will be a date in milliseconds format from Date.now(). If the reuslts relative property is false, the value will be the absolute milliseconds value of the parsed string (for example, 1 seconds will be returned as 1000).

Format

Format a result object returned from parse in a human readable format.

var result = dateparser.parse('every 1 hour');
console.log(dateparser.format(result));

License

Copyright (c) 2015 by Jeff Haynie. Licensed under the Apache-2.0 license.

Keywords

date

FAQs

Package last updated on 14 Aug 2015

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