Git Product home page Git Product logo

timeslots's Introduction

JS Timeslot

Get free time patches between given time range

Installation

npm install jstimeslot

Usage

const Timeslot = require('jstimeslot');

// Pass 'start' and 'end' in UNIX TIME (Milliseconds)
const maxRange = {
  'start': 1483228800000, // Sunday, 1 January 2017 00:00:00:000 GMT
  'end': 1483315199999 // Sunday, 1 January 2017 23:59:59:999 GMT
}

const usedSlots = [
  { 'start': 1483232400000, 'end': 1483236000000 }, // 1am - 2am
  { 'start': 1483237800000, 'end': 1483248600000 }, // 2:30am - 5:30am
  { 'start': 1483270200000, 'end': 1483295400000 }, // 11:30am - 6:30pm
];


const manager = new Timeslot(maxRange, usedSlots);

Available timeslots

Find free time-slots from the provided max range and used slots

manager.freeSlots 
/* [ 
  { start: 1483228800000, end: 1483232400000 }, // 0am - 1am
  { start: 1483236000000, end: 1483237800000 }, // 2am - 2:30 am
  { start: 1483248600000, end: 1483270200000 }, // 5:30 am - 11-30am
  { start: 1483295400000, end: 1483315199999 }  // 6:30 pm - 11:59pm
] */

Add more used slots

const additionalUsedSlots = [
  {'start': 1483228800000, 'end': 1483232400000 }, // 0am - 1am
  { 'start': 1483236000000, 'end': 1483237900000 } // 2am - 2:31:40am
];

manager.addUsedSlots(additionalUsedSlots);

manager.freeSlots 
/* [ 
  { start: 1483248600000, end: 1483270200000 }, // 5:30 am - 11-30am
  { start: 1483295400000, end: 1483315199999 }  // 6:30 pm - 11:59pm
] */

Time-slots between

Get free time slots between a time range (must be a subset of max range)

manager.getFreeSlotsBetween({ 'start': 1483237799990, 'end': 1483286400000 }); // 2:29:59 am - 4 pm
/* [ 
  { start: 1483248600000, end: 1483270200000 }, // 5:30 am - 11-30am 
] */

Overlapping slots

Find overlapping used slots (returns an array of arrays)

manager.getOverlappingUsedSlots();
/*
[ 
  [ 
    { start: 1483237800000, end: 1483248600000 }, // 2:30am - 5:30am 
    { start: 1483236000000, end: 1483237900000 }  // 2am - 2:31:40am
  ]     
]
*/

timeslots's People

Contributors

surajshetty3416 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

govind-jangid

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.