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

work-time-library

v1.1.2

Published

Library for counting business time

Downloads

46

Readme

Work-time-library

Work-time-library is plugin to count business time.

DEMO

Instalation


With NPM

npm i work-time-library

Usage


import FindWorkingPeriodAdd from 'work-time-library/FindWorkingTimeAdd'
import FindWorkingPeriodDiff from 'work-time-library/FindWorkingTimeDiff'

//or
const FindWorkingPeriodAdd = require('work-time-library/FindWorkingTimeAdd')
const FindWorkingPeriodDiff = require('work-time-library/FindWorkingTimeDiff')

Setup for FindWorkingPeriodDiff() function


You should put 3 params in function to get the result. They are:

  • ValidatyRange array(startDate and endDate).
  • Time segments array.
  • FunctionOptions, where you can define the time format output, that you want(hours,minutes or seconds).

Setting validatyRange

// Create your validatyRange array as string array

var validatyRange = [
    "2021-8-10", // 10 August, 2021
    "2021-8-16" // 16 August, 2021
],

Setting time segments

There are 3 types of time segments: ,

  • Segment for ordinary week days.
    // only one
  • Segments for extra days(for example if you want to make to change period of working time for 7 of May).
    // as many as you want
  • Segment for holidays.
    // only one

You should put all your segments to Segment array

// Segment for ordinary week days structure:

{
    name: 'Segment1LvlWorkingTime',

    description: '1 lvl segment for ordinary week days',

    status: true, // if status == false, segment wont be available

    validityStartDate: "2010-1-1", 
        // days from validatyRange array will be counted only within this two dates
    validityEndDate: "2050-1-1", 

    segmentWorkingPeriods: {

        Monday: [["7:00:00","10:00:00"],["11:00:00","18:00:00"]], // You can define as many periods as you want

        Tuesday: [["7:00:00","10:00:00"],["11:00:00","18:00:00"]],

        Wednesday: [["7:00:00","10:00:00"],["11:00:00","18:00:00"]],

        Thursday: [["7:00:00","10:00:00"],["11:00:00","18:00:00"]],

        Friday: [["7:00:00","10:00:00"],["11:00:00","18:00:00"]],

        Saturday: null, 
            // If you want to make holiday, enter "null"

        Sunday: null
    },
    segmentLevel: 1 // !
}
// Segment for extra days:

{
    name: 'Segment2LvlWorkingTime',

    description: '2 lvl segment for extra days',

    status: true,

    segmentWorkingPeriod: [["6:00:00","10:00:00"],["12:00:00","17:00:00"]],

    segmentValidatyDays: [ 
        "2021-8-12",
        "2021-8-16"
    ]
    // Here you should define the dates, when that schedule will be available

    segmentLevel: 2 // !
}
// Segment for holidays:

{
    name: 'Segment3Lvl',

    description: '3 lvl segment for holidays',

    status: true,

    segmentValidatyDays: [
        "2021-8-10", // 10 August, 2021
        "2021-8-15" // 15 August, 2021
    ]

    segmentLevel: 3
        // ! 
},

Setting FunctionOptions

var FunctionOptions = {
    format: 'Seconds', //Seconds | Minutes | Hours
}

Final usage of FindWorkingPeriodDiff() function:

var result = FindWorkingPeriodDiff(ValidatyRange, Segments, FunctionOptions)

==========================================================

Setup for FindWorkingPeriodAdd() function


You should put 3 params in function to get the result. They are:

  • StartDate.
  • Time segments array.
  • AdditionalSecs.

Setting StartDate

// Create your StartDate as ISO string

var StartDate = "2021-08-10T16:00:00"

Setting time segments

Set time segments exactly like in FindWorkingPeriodDiff() fuction
You can find options above

Setting AdditionalSecs

var AdditionalSecs = '3600' or 3600 // 3600 secs - 1 hour

Final usage of FindWorkingPeriodAdd() function:

var result = FindWorkingPeriodAdd(ValidatyRange, Segments, FunctionOptions)