Skip to content

ChronoRange is a node.js module for parsing and validating date ranges in a [chrono](https://github.com/wanasit/chrono) compatible format.

Notifications You must be signed in to change notification settings

cedrictailly/chrono-range

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

ChronoRange

ChronoRange is a simple library to parse and validate date ranges.

Installation

ChornoRange can be installed using npm

npm install chrono-range

Usage

ChronoRange can be used to validate a date in a predefined range with the check method.

const ChronoRange = require('chrono-range');

const range = new ChronoRange('between Jan 1 2001 and Dec 31 2011 excluded');

// will return `true`
const beforeFirst = range.check(new Date('2001-01-01'));
// will return `false`
const firstDay = range.check(new Date('2011-12-31'));

You can also handle relative dates:

// `before` range example
const range1 = new ChronoRange('before 10 days ago');

// `after` range example with keyword `excluded`
const range2 = new ChronoRange('after 10 minutes ago excluded');

ChronoRange also provide methods to check if a file is in the specified range, checkFile supporting async/await and checkFileSync for synchronous calls.

const range = new ChronoRange('after Jan 1 2020');

// will return `true`, async version
const newerFile = await range.checkFile('file_1.txt');
// will return `false`, sync version
const olderFile = range.checkFileSync('file_2.txt');

About

ChronoRange is a node.js module for parsing and validating date ranges in a [chrono](https://github.com/wanasit/chrono) compatible format.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published