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 = ; // Supply the constructor with instructions on how to parse your date objects// The function must return an object that matches the 'Range' interface belowvar clash = { return start: dates end: datee id: dateid }; // Detect the clashesvar clashes = clash; // Make the clash 'window'/'extremities' fall on particular days of the week// 0 = Sunday, 6 = Saturdayvar clashes = clash; // Returns an object of type Clashes that looks like: start: Tue Sep 15 2015 00:00:00 GMT+ end: Thu Sep 24 2015 00:00:00 GMT+ '1': date: Tue Sep 15 2015 00:00:00 GMT+ clashes: ... ... '10': date: Tue Sep 24 2015 00:00:00 GMT+ 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
;
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:
{ return start: myObjectstartDate end: myObjectendDate id: myObjectid firstName: myObjectfirstName lastName: myObjectlastName ;} var clash = rangeGetter;
Flatten
The function that does all of the work.
Takes an array of objects that your rangeGetter
function can parse.
=> 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