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

availability-schedule

v1.1.0

Published

A simple availability schedule library

Downloads

389

Readme

availability-schedule

A simple availability schedule library for JS

Installation

npm install availability-schedule --save

Import

const AvailabilitySchedule = require('availability-schedule');

For TypeScript:

import AvailabilitySchedule = require('availability-schedule');

If that throws an error (e.g. TS1202: Import assignment cannot be used when targeting ECMAScript modules), try a regular import statement:

import AvailabilitySchedule from 'availability-schedule';

Usage

const schedule = new AvailabilitySchedule('2017-01-09T00:00:00Z', '2017-01-16T00:00:00Z'); // Second week of Jan 2017
schedule.addWeeklyRecurringAvailability('2017-01-04T09:00:00Z', '2017-01-04T17:00:00Z', [1, 2, 3, 4, 5]); // Mon-Fri 9am-5pm UTC, starting on Wed Jan 4th
schedule.addAvailability('2017-01-14T12:00:00Z', '2017-01-14T15:00:00Z'); // Sat Jan 14 12pm-3pm UTC

schedule.getAvailabilities('+0100');
/*
[
  {start: '2017-01-09T10:00:00+01:00', end: '2017-01-09T18:00:00+01:00'},
  {start: '2017-01-10T10:00:00+01:00', end: '2017-01-10T18:00:00+01:00'},
  {start: '2017-01-11T10:00:00+01:00', end: '2017-01-11T18:00:00+01:00'},
  {start: '2017-01-12T10:00:00+01:00', end: '2017-01-12T18:00:00+01:00'},
  {start: '2017-01-13T10:00:00+01:00', end: '2017-01-13T18:00:00+01:00'},
  {start: '2017-01-14T13:00:00+01:00', end: '2017-01-14T16:00:00+01:00'}
]
*/

schedule.isAvailable('2017-01-14T15:00:00+01:00', '2017-01-14T16:00:00+01:00'); // true

Reference

The library is fully timezone-aware. Dates can be provided in any timezone and can be mixed.

Tip: Use the toISOString method of the Date class or the moment library to generate ISO 8601 date strings.

constructor (startDate, endDate)

  • startDate Start date of the schedule as an ISO 8601 string
  • endDate End date of the schedule as an ISO 8601 string

addAvailability (startDate, endDate)

  • startDate ISO 8601 string
  • endDate ISO 8601 string

addWeeklyRecurringAvailability (startDate, endDate, repeatWeekdays)

  • startDate ISO 8601 string
  • endDate ISO 8601 string
  • repeatWeekdays Array of integers that indicate the weekdays on which the availability is repeated. 1 = Mon, 7 = Sun (in the same time zone as startDate).

Start and end dates may be earlier than the start date passed to the constructor.

removeAvailability (startDate, endDate)

  • startDate ISO 8601 string
  • endDate ISO 8601 string

Use this to remove a time range from any existing availabilities. For example, call this for scheduled appointments or meetings.

getAvailabilities (timezone = '+0000')

  • timezone Accepts just the timezone offset such as "-05:00" as well as a full time stamp that includes the offset (e.g. "2000-01-01T00:00:00-04:00")

Returns all availabilities as an array of {start: date string, end: date string} objects in chronological order.

isAvailable (startDate, endDate)

  • startDate ISO 8601 string
  • endDate ISO 8601 string

Returns true if the given time range falls within any availability.