Socket
Socket
Sign inDemoInstall

slot-calculator

Package Overview
Dependencies
1
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    slot-calculator

Calculate time slots for your users to choose from.


Version published
Weekly downloads
13K
increased by18.65%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Slot Calculator

GitHub Workflow Status npm

Calculate time slots for your users to choose from.

  • Intersect availabilities of multiple users/resources.
  • Full timezone support.
  • Blazing fast (usage of ES6 Sets, Maps and efficient data structures).
  • Works great with Luxon and V-Calendar.

Table of contents

Installation

npm install slot-calculator

Documentation

View the JS/TS reference

TypeScript language support in your IDE is sufficient to make use of this package's types and annotations.

Examples

import { getSlots } from "slot-calculator"

Basic usage

const { slots } = getSlots({
  from: DateTime.utc(2022, 1, 1).toISO(),
  to: DateTime.utc(2022, 1, 8).toISO(),
  availability: [
    {
      from: DateTime.utc(2022, 1, 1, 15).toISO(),
      to: DateTime.utc(2022, 1, 1, 16).toISO(),
    },
  ],
  duration: 60,
})

With user availabilities

const { slots } = getSlots({
  from: DateTime.utc(2022, 1, 1).toISO(),
  to: DateTime.utc(2022, 1, 8).toISO(),
  availability: [
    {
      day: "Monday",
      from: "14:00",
      to: "16:00",
      metadata: {
        user: "Alice",
      },
    },
    {
      day: "Monday",
      from: "15:00",
      to: "17:00",
      metadata: {
        user: "Bob",
      },
    },
  ],
  duration: 60,
})

With timezones

const { slots } = getSlots({
  from: DateTime.utc(2022, 1, 1).toISO(),
  to: DateTime.utc(2022, 1, 8).toISO(),
  outputTimezone: "Europe/Paris",
  availability: [
    {
      day: "Monday",
      from: "14:00",
      to: "16:00",
      timezone: "America/New_York",
    },
  ],
  duration: 60,
});

Helper variables

const { slots, allDates, availableDates, slotsByDay, timeTaken } = getSlots(config)
  • slots: An array of available slots. Only use this as a starting point for manipulating the output.
  • allDates: An array of dates, including unavailable ones, between the from and to configuration variables. Use this to allow users to specify their own datetime, but within your chosen bounds.
  • availableDates: An array of available dates. Use this to mark on a calendar which dates can be selected.
  • slotsByDay: Once a user has selected a date, use this object to easily find the slots for that day.
  • timeTaken: Worried that the number crunching is slowing down your app? Monitor this variable to see the time taken by slot calculator.

Keywords

FAQs

Last updated on 12 Jun 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc