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

bizniz

v1.0.0

Published

Constant-time business utilities for the western work week

Downloads

9

Readme

bizniz

Constant-time business utilities for the western work week

Travis build status Code Climate Test Coverage Dependency Status devDependency Status

About

Utilities to do calculations with work weeks are common on the 'net, but many of them loop over every day in a given interval for their calculations. Loops are easy for humans to write, but slow for computers to resolve. In fact, the larger the interval, the longer those looping calculations takes.

This library is a collection of constant-time utilities that produce the same result as the looping approach, yet are computed the same speed no matter how large your time scale is. Three days will be computed just as fast as a million days.

Getting Started

Install this library with npm.

npm install bizniz

Import it into your application, and use the main export.

import bizniz from 'bizniz';

const daysBetween = bizniz.addWeekDays(day, 20);

Inclusive and Exclusive Intervals

Working with intervals of time is a surprisingly nuanced topic. When a function accepts two dates, there's an option question of whether each of those days is included in the interval or not. If one of the days is included, then that's called an inclusive endpoint. Otherwise, it's an exclusive endpoint.

For instance, consider the question of how many days are between March 1, 2016, and March 1, 2016. If the start and end are both inclusive, then the answer is

  1. If either, or both endpoints are exclusive, then the answer is 0.

Using any algorithm that involves two dates may produce unexpected results if you're not sure how it treats the endpoints.

There is much discussion about the endpoints of time intervals. Many people believe that exclusively using inclusive starts and exclusive ends lead to the least headaches. I agree with them, which is why the two interval functions in this library, weekDaysBetween and weekendDaysBetween, are calculated with an inclusive start and an exclusive end.

API

isWeekDay( date )

Returns a boolean representing whether or not date is a week day. date must be a JavaScript Date object.

isWeekendDay( date )

Like isWeekDay, but for weekends. Pass in a date, and you'll get back a boolean.

weekDaysBetween( startDate, endDate )

Computes the number of week days between startDate and endDate. If endDate is after startDate, then the number returned will be positive. Otherwise, it will be negative.

weekendDaysBetween( startDate, endDate )

Just like weekDaysBetween, but for the weekend.

addWeekDays( date, days )

Pass in days, which is a number of week days, and a date, and a new Date object will be returned representing the addition of the two. Accepts positive and negative days.

subtractWeekDays( date, days )

Just like addWeekDays, but in the opposite direction. It, too, accepts positive and negative values.

dateIsBefore( startDate, endDate )

Returns true is startDate comes before endDate. Otherwise, it returns false.

daysBetween( startDate, endDate )

Returns the total number of days between startDate and endDate, including both week days and weekend days. If endDate comes before startDate, then the value will be negative.

addDays( date, days )

Adds days number of days to date. Returns a new Date object.