npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ssense/sscheduler

v1.3.2

Published

Flexible scheduler to find free time slots in the schedule of a resource

Downloads

3,223

Readme

sscheduler

Build Status Coverage Status Latest Stable Version Known Vulnerabilities

Flexible scheduler to find free time slots in the schedule of a resource (which could be a person, a meeting room, a car, etc...)

sscheduler can also intersect the availability of multiple resources in order to find the time slots at which all the resources are available.

Installation

npm install @ssense/sscheduler

Basic usage

As an example, let's say that we want to book a 1 hour appointment with a doctor in the month of february considering that:

  • We can only book on weekdays from 9AM to 5PM

  • We can't book between noon and 1PM (lunch time !)

  • The doctor is on vacation the week of the 20th

  • There are already two one-hour appointments booked on February 1st at 1PM and 2PM

import {Scheduler} from '@ssense/sscheduler';

const scheduler = new Scheduler();
const availability = scheduler.getAvailability({
    from: '2017-02-01',
    to: '2017-03-01',
    duration: 60,
    interval: 60,
    schedule: {
        weekdays: {
            from: '09:00', to: '17:00',
            unavailability: [
                { from: '12:00', to: '13:00' }
            ]
        },
        unavailability: [
            // two different types of unavailability structure
            { from: '2017-02-20 00:00', to: '2017-02-27 00:00' },
            { date: '2017-02-15', from: '12:00', to: '13:00' }
        ],
        allocated: [
          { from: '2017-02-01 13:00' , duration: 60 },
          { from: '2017-02-01 14:00' , duration: 60 }
        ]
    }
});

The returned value is a structure that looks like the following:

{
  '2017-02-01': [
    { time: '09:00', available: true },
    { time: '10:00', available: true }
    // ...
  ]
  // ...
}

Options

The possible options for the getAvailability function are:

Example:

{
  monday: {
    from: '09:00',
    to: '17:00',
    unavailability: [
      { from: '12:00', to: '13:00' }
    ]
  },
  custom_schedule: [
    { "date": "2017-01-23", "from": "12:00", "to": "17:00" },
  ]
}

Schedule intersection

Using the same example as before, let's say that we also need to book a room for our appointment.

So, we need to intersect the doctor's availability times with the room's availability times, considering that:

  • We can only book the room on weekdays from 8AM to 8PM

  • The room is out of service from February 6th to February 16th

import {Scheduler} from '@ssense/sscheduler';

const scheduler = new Scheduler();
const availability = scheduler.getIntersection({
    from: '2017-02-01',
    to: '2017-03-01',
    duration: 60,
    interval: 60,
    schedules: [
        // The doctor's schedule
        {
            weekdays: {
                from: '09:00', to: '17:00',
                unavailability: [
                    { from: '12:00', to: '13:00' }
                ]
            },
            unavailability: [
                { from: '2017-02-20 00:00', to: '2017-02-27 00:00' }
            ],
            allocated: [
              { from: '2017-02-01 13:00' , duration: 60 },
              { from: '2017-02-01 14:00' , duration: 60 }
            ]
        },

        // The room's schedule
        {
            weekdays: {
                from: '08:00', to: '20:00',
            },
            unavailability: [
                { from: '2017-02-06 00:00', to: '2017-02-16 00:00' }
            ]
        }
    ]
});

Authors

  • Mickael Burguet - Senior Developer - rundef

License

This project is licensed under the MIT License - see the LICENSE.md file for details.