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

@gund/time-slots

v1.0.3

Published

> Small library to generate slots for a date range between a time range with optional interval

Downloads

414

Readme

@gund/time-slots

Small library to generate slots for a date range between a time range with optional interval

Travis CI Coverage Maintainability Npm Npm Downloads Licence semantic-release

This is a small utility library that allow you to easily generate time slots and also exclude from generated time slots already existing time slots.

It has "zero" dependencies but requires a small set of date functions to operate which you can provide via DateAdapter. And there is already existing date-fns adapter that you can use out of the box.

Install

$ npm install @gund/time-slots

Optionally install date-fns if you want to use out of the box provider:

$ npm install date-fns

Setup

First make sure to provide a small set of date functions called DateAdapter that is needed for this library to work:

import { provideDateAdapter } from '@gund/time-slots';

provideDateAdapter(...); // Your DateAdapter is here

Optionally you may import and use existing date-fns adapter:

import { provideDateAdapter } from '@gund/time-slots';
import { dateFnsAdapter } from '@gund/time-slots/date-adapter/date-fns';

provideDateAdapter(dateFnsAdapter);

Use

Generation of slots

You can generate slots for a date range DateRange between a time range TimeRange with optional time interval TimeInterval:

import { generateTimeSlots, DateRange, TimeRange } from '@gund/time-slots';

const slots = generateTimeSlots(
  DateRange.fromDates(new Date(2020, 10, 15), new Date(2020, 10, 20)),
  TimeRange.fromTimeStrings('9:00', '17:30'),
);

// Now slots will contain array of `TimeRange`
// between 15.11.2020 to 20.11.2020
// with every day from 9am till 5:30pm
console.log(slots);

With time interval

To slice every day into intervals you can add TimeInterval argument:

import {
  generateTimeSlots,
  DateRange,
  TimeRange,
  TimeInterval,
} from '@gund/time-slots';

const slots = generateTimeSlots(
  DateRange.fromDates(new Date(2020, 10, 15), new Date(2020, 10, 16)),
  TimeRange.fromTimeStrings('9:00', '17:30'),
  TimeInterval.minutes(30),
);

// Now slots will contain array of `TimeRange`
// between 15.11.2020 to 20.11.2020
// with every day sliced in 30 mins intervals from 9am till 5:30pm
console.log(slots);

Exclusion of existing slots

You can also exclude from an array of slots another array of slots. The exclusion of a slot will happen as long as it intersects with a slot from another array.

import { excludeTimeSlots } from '@gund/time-slots';

const allSlots = [...];
const bookedSlots = [...];

const availableSlots = excludeTimeSlots(allSlots, bookedSlots);

// Result will have only slots from `allSlots` that
// do not intersect with any slots in `bookedSlots`
console.log(availableSlots);

Build

Run nx build to build the project. The build artifacts will be stored in the dist/ directory. Use the --prod flag for a production build.

Running unit tests

Run nx test to execute the unit tests via Jest.

Run nx affected:test to execute the unit tests affected by a change.

Understand your workspace

Run nx dep-graph to see a diagram of the dependencies of your projects.