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

react-date-range-divider

v1.0.2

Published

[![npm version](https://badge.fury.io/js/react-date-range-divider.svg)](https://badge.fury.io/js/react-date-range-divider)

Downloads

3

Readme

react-date-range-divider

npm version

npm downloads

A react component for divide a date interval into equally distributited intervals at a day level.

Installation

npm i react-date-range-divider --save

Usage

Quick Examples

import { DateRangeDivider, IMiddleDateInterval } from 'react-date-range-divider';
const FooComponent = () => {
    const [intervals, setIntervals] = useState<IMiddleDateInterval[]>([]);
    const numOfDivisios = 2;
    const startDate = new Date("2020/05/11"); // YYYY/MM/DD 
    const endDate = new Date("2020/05/15");  // YYYY/MM/DD 
    return (
        <DateRangeDivider
            divisions={numOfDivisios}
            startDate={startDate}
            endDate={endDate}
            onDivisionsChange={(resultIntervals: IMiddleDateInterval[]) => {
                // Do what you need with intervals
                setIntervals(() => resultIntervals);
            }}
        />
    )
};

Warning

Since it divides in entire days a non possible Int division (with no decimals in result) will aproximate the first interval to the next day. In this case the result will be:

  • 11/05/2020 - 00:00:00 => 13/05/2020 - 23:59:59 (3 days including start and end)
  • 14/05/2020 - 00:00:00 => 14/05/2020 - 23:59:59 (2 days including start and end)

5 days in total from 11/05/2020 - 15/05/2020. (DD/MM/YYYY)

calcRegularIntervals Function

If only need to divide intervals without the component, the function can be imported alone.

import { calcRegularIntervals, IMiddleDateInterval } from 'react-date-range-divider';

const startDate = new Date("2020/05/11"); // YYYY/MM/DD 
const endDate = new Date("2020/05/15");  // YYYY/MM/DD 
const numOfDivisios = 2;

const intervals: IMiddleDateInterval[] = calcRegularIntervals(startDate, endDate, numOfDivisios); // number to divide is 1 by default

Documentation

Import

import { DateRangeDivider } from 'react-date-range-divider';

Error Handler

By passing a endDate lower than the startDate or giving a divisionNumber higher than the number of days in between parent interval, the component will use the current day divided in one

Props

| Name | Type | Description | | :---------: | :----------------------------------------: | :-----------------------------------: | | divisions | number | Number of division desired of the given period (If this number is higher than the number of days available in the period will take 1 as default) | | startDate | Date | Start date of the parent interval (will convert to the beggining of the passes day. ex: 2020/05/14:12:14:00 => 2020/05/14-00:00:00) | | | endDate | Date | Finish Date of the parent interval (will convert to the beggining of the passes day. ex: 2020/05/14:12:14:00 => 2020/05/14-23:59:59) | | | onDivisionsChange | (intervals: IMiddleDateInterval[]) => void | callback that passes the resultant intervals as argument |

Types

| Name | Type | Description | | :---------------------: | :-----------------------------: | :-----------------------------------: | | IMiddleDateInterval | {start: Date, end: Date} | Dates resultant of division calculus |