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

opening-sign-shifts-to-schedule

v1.1.3

Published

Opening Sign Project: takes rules about shift hours and outputs it as a weekly schedule

Downloads

1

Readme

Opening Sign: shifts to schedule library

Purpose

This library has the means to be used by the Opening Sign project, and is here to convert shift rules inputted by the user into data for a weekly schedule.

Installation

npm install opening-sign-shifts-to-schedule

Usage

Feed it shift rules! It outputs a weekly schedule.

schedule(rules);

Schedule() function

Input

rules: [
  {
    // Every week, from Monday to Thursday, the opening times are from 8:00 to 18:00
    repeating: "weekly",
    repeatingDates: ["mon", "tue", "wed", "thu"],
    isClosed: false,
    shift: [
      28800, // 08:00, stored as seconds past midnight
      64800, // 18:00
    ],
  },
  {
    // On 06/22/2021, the opening times are from 20:30 to 03:00 (night shift)
    repeating: "exceptional",
    repeatingDates: [
      1624320000, // Epoch timestamp (seconds) for 06/22/2021 at 00:00 (time is not relevant, only date matters)
      // etc...
    ],
    isClosed: false,
    shift: [
      // a pair of seconds past midnight on the RepeatingDates
      73800, // 20:30, stored as seconds past midnight
      97200, // 27:00 (24:00 + 03:00), the next day. As this is over 1440 minutes (=24h) it will be detected as a night shift
    ],
  },
  {
    // Every Monday, it is closed from 12:00 to 14:00
    repeating: "weekly",
    repeatingDates: ["mon"],
    isClosed: true,
    shift: [
      43200, // 12:00 closes
      50400, // 14:00 opens again
    ],
  },
];

The shift is to be stored as a pair, it will define the start and the end of the shift (reversed when isClosed: true)

Output

schedule: {
	mon: [
		28800, // 08:00 stored as seconds past midnight
		43200, // 12:00 closes
		50400, // 14:00 opens again
		64800  // 18:00
	],
	tue: [
		28800, // 08:00, stored as seconds past midnight
		64800  // 18:00
	],
	wed: [
		28800, // 08:00, stored as seconds past midnight
		64800  // 18:00
	],
	thu: [
		28800, // 08:00, stored as seconds past midnight
		64800  // 18:00
	],
	exceptional: [
		{
			date: 1624320000, // On 06/22/2021
			overrideRegular: false, // here, it will follow regular breaks overlapping with it (if break from 00:00 to 2:00, will write 20:30-00:00-2:00-3:00)
			opening: [
				73800,   // 20:30, stored as seconds past midnight
				97200    // 27:00 (24:00 + 03:00), the next day. As this is over 1440 minutes (=24h) it will be detected as a night shift
			]
		}
	]
}

Roadmap

  • [ ] exceptional shifts support
  • [ ] merging overlapping shifts
  • [x] unit tests
  • [x] day shifts support
  • [x] closing shifts support
  • [x] subtracting closing shifts to opening shifts
  • [x] night shifts support

Changelog

1.1.x - refactoring files

  • each side function now has its own file
  • tests are now in multiple files
  • weekDays is exported so you can use it in your project (it's an array of 3 letters weekdays)
  • every function is exported too

1.0.x - Initial version!

  • Working weekly shifts.
  • Working night shifts.
  • Working closing shifts.