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

day-interval-function

v1.0.6

Published

I wanted to create a function that I could just enter which days and at what range of time during those days a function would run. Also this function would run at that time every week. For example: If I had a store that is open between 10:00 - 15:00 every

Downloads

20

Readme

🕜 Day/Time interval checker

I wanted to create a function that I could just enter which days and at what range of time during those days a function would run. Also this function would run at that time every week. For example: If I had a store that is open between 10:00 - 15:00 every monday, I would like to run a function that changes from "closed" paragraph to an "open" paragraph and vice versa.

So I created this npm package! Hope it works well! Keep on reading to see how you can implement it and test it out in the Live demo.

What’s In This Document

⚡️ Install:

In your root folder for you project, open up an terminal and enter:

npm i day-interval-function

💻 How to use this function

1. Import the function into you project.

import { intervalChecker } from "day-interval-function";

2. Create the options oject containing your settings.

Write your timezone and time format. This package supports both 24 and 12 hour format.

const options = {
myTimeZone: "Europe/Stockholm",
timeFormat: 24,
}

3. Create the dayAndTimeSlots variable

Enter which days and time slots that you want your own function to run. First string in time slot array is the start time and the second is the ending time. Doesnt support range over midnight. For that you need to change two days to true.

const daysAndTimeSlots = [
 {
 sunday: true,
 time: ["05:00", "22:00"],
 },
 {
 monday: false,
 time: ["05:00", "22:00"],
 },
 {
   tuesday: true,
 time: ["05:00", "22:00"],
 },
 {
 wednesday: false,
 time: ["15:00", "21:00"],
 },
 {
 thursday: true,
 time: ["05:00", "22:00"],
 },
 {
 friday: false,
 time: ["20:00", "21:00"],
 },
 {
 saturday: false,
 time: ["11:00", "02:59"],
 },
 ]

The function checks which days are true and if that day is today. Then it checks if the current time is within the range that you have selected.

IF YOU ARE USING THE 12 HOUR FORMAT Remember that you have to change the option timeformat in the first step to 12. You also have to write your time slots in this way:

time: ["09:00 am", "09:00 pm"],

Otherwise the function cannot run and will display an console log telling you so.

4. Run the function

As you can see the function you get require four arguments although one is optional. First is the days and time slots you have selected, second is the options, third is what function you want to run at that given time, and fourth is what function you want to run when time is NOT in your time slots. It is possible to run without the functionWithinRange or functionOutOfRange but remember to defined that as null before you continue.

intervalChecker(daysAndTimeSlots, options, functionWithinRange, functionOutOfRange)

Here is an working example with Dan's tutorial that runs every 10 minutes. Remember that you need to implement Dans custom hook useInterval.

useInterval(() => {
 intervalChecker(daysAndTimeSlots, options, functionWithinRange, fucntionOutOfRange)
}, 600000)