Socket
Socket
Sign inDemoInstall

date-clashes

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-clashes

A simple API for detecting overlapping dates


Version published
Weekly downloads
18
Maintainers
1
Weekly downloads
 
Created
Source

date-clashes

A simple API for detecting overlapping dates

Installation

npm install date-clashes --save

Usage

var myDates = [
   { s: /* Date */, e: /* Date */ , id: 1 },
   { s: /* Date */, e: /* Date */ , id: 2 },
   ...
];

var DateClash = require("date-clashes");

// Supply the constructor with instructions on how to parse your date objects
// The function must return an object that matches the 'Range' interface below
var clash = new DateClash.Clash(date => { return { start: date.s, end: date.e, id: date.id } });

// Detect the clashes
var clashes = clash.flatten(myDates);

// Make the clash 'window'/'extremities' fall on particular days of the week
// 0 = Sunday, 6 = Saturday
var clashes = clash.flatten(myDates, { startDay: 1 /* Monday */, endDay: 0 /* Sunday */ });

// Returns an object of type Clashes that looks like:
{
    start: Tue Sep 15 2015 00:00:00 GMT+0800 (W. Australia Standard Time),
    end: Thu Sep 24 2015 00:00:00 GMT+0800 (W. Australia Standard Time),
    
    '1': { date: Tue Sep 15 2015 00:00:00 GMT+0800 (W. Australia Standard Time),
     clashes: [ ... ] },
     ...
    '10': { date: Tue Sep 24 2015 00:00:00 GMT+0800 (W. Australia Standard Time),
     clashes: [ ... ] },
}


interface Clashes {
    start: Date; // The floored version of the earliest date in your array
    end: Date; // The ceiling version of the latest date in your array
    [dayNumber: number]: { date: Date, clashes: Range[] }
}

interface Range {
    start: Date;
    end: Date;
    [key: string]: any;
}

API

Constructor
constructor(rangeGetter?: RangeGetter);
RangeGetter

A function that takes an object and returns an object that date-clashes can understand (Range)
The object must contain a start and end property which must be Date objects.

Example:

function rangeGetter(myObject) {
    return {
        start: new Date(myObject.startDate),
        end: new Date(myObject.endDate),
        id: myObject.id,
        firstName: myObject.firstName,
        lastName: myObject.lastName
    };
}

var clash = new DateClash.Clash(rangeGetter);
Flatten

The function that does all of the work.
Takes an array of objects that your rangeGetter function can parse.

function flatten(dates: Array<any>, options?: Options) => Clashes;
Options

An optional object that has two optional properties:
startDay and endDay
These options will determine the day number of outer-extremities of the returned Clashes object.

{
    startDay: number,
    endDay: number
}

License

MIT

Keywords

FAQs

Package last updated on 29 Sep 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

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