0.1.1 • Published 3 years ago

dates-ranger v0.1.1

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

dates-ranger

Dates-ranger helps you find date intervals and calculate duration much easier than ever. This library is light-weighted and dependency free, and it is purely developed in Typescript.

Table of Contents

Install

This node module is ditributed to npm with bi-weekly release in the year of 2021

You can install it by running:

npm install -g dates-ranger

Usage

Background

In various use cases, people would like to query data in a specific period, such as "Week to Date", "Last Month" or "Recent Three Days", It is hard to find them as TODAY moves forward. And in many calendar apps, people are interested in the duration between given dates. All is made easy with this library.

Interval API

Interval API introduces DateInterval(standAt?:string) Object for methods returning Array([startDate:string, endDate:string]). These are:

const interval = new DateInterval('12/12/2020'); //intialize an object with standAt='12/12/2020', default is TODAY
interval.getIntervalForYesterday(); //[ '12/11/2020', '12/11/2020' ]
interval.getIntervalForWeekToDate((newCycleDay = 'Mon')); //[ '12/7/2020', '12/12/2020' ]
interval.getIntervalForWeekToDate((newCycleDay = 'Sun')); //[ '12/6/2020', '12/12/2020' ]
interval.getIntervalForWeekToDate((newCycleDay = 'Sat')); //[ '12/12/2020', '12/12/2020' ]
interval.getIntervalForPreviousWeek(); //[ '11/30/2020', '12/6/2020' ]
interval.getIntervalForMonthToDate(); //[ '12/1/2020', '12/12/2020' ]
interval.getIntervalForPreviousMonth(); //[ '11/1/2020', '11/30/2020' ]
interval.getIntervalForYearToDate(); //[ '1/1/2020', '12/12/2020' ]
interval.getIntervalForPreviousYear(); //[ '1/1/2019', '12/31/2019' ]
interval.getIntervalForRecentNDays((n = 5)); //[ '12/8/2020', '12/12/2020' ]
interval.getIntervalForRecentNDays((n = 5), (inclusive = true)); //[ '12/7/2020', '12/12/2020' ]

Duration API

Duration API introduces Duration(standAt?:string) Object for methods returning counts:number. These are:

const duration = new Duration(); //by default, Today is where we stand at
duration.btwTodayAndDestination(new Date()); //return 0
duration = new Duration('12/12/2020'); //intialize an object with standAt='12/12/2020', so you see this date as TODAY
duration.btwTodayAndDestination('12/13/2020'); //return 1
duration.btwTodayAndDestination('12/7/2020'); //return -5

//static method
Duration.btwDates('12/13/2020', '12/10/2020'); //return -3
Duration.btwDates(new Date('12/13/2020'), new Date('11/30/2020')); //return -13
Duration.btwDates(...new DateInterval().getIntervalForPreviousYear()); //return 364

More usage info, please consult documentation and unit test.

TODO

TaskExpected Delivery
TimeInterval to provide utilities for time interval operations12/31/2020
Date Formater to let users easily format the output dates1/15/2021

Maintainer

@cstechfoodie

Contributing

Please contribute! Look at the issues.

License

MIT © 2020 Shunyu Wang

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago