🗓⚡️ Date Streaks
A package to find streaks from a list of dates.
;const dates ='01/01/2018''01/02/2018''01/04/2018';// or summary(dates) -> accepts an array as well;
currentStreak: 0longestStreak: 2streaks: 2 1todayInStreak: falsewithinCurrentStreak: false
# with npm:npm install date-streaks --save# or with yarn:yarn add date-streaks
date-streaks comes with three functions to get various information about streaks throughout a list of dates.
Summary finds streaks within a list of dates and returns the current streak, the longest streak, whether today is in the streak, and whether the current streak is still valid.
The logic for
withinCurrentStreak is whether today or yesterday appears in the list. Since a user would still be in a streak if they completed an event yesterday and still had yet to complete it today.
Let's pretend today is 01/07/2018 for this example:
;const dates ='01/01/2018''01/02/2018''01/03/2018''01/06/2018';; // or summary(dates) -> accepts an array as well
currentStreak: 1longestStreak: 3streaks: 3 1todayInStreak: falsewithinCurrentStreak: true
Streak ranges finds the start and end dates of each streak, in addition to the duration of each of the streaks.
;const dates ='01/01/2018''01/02/2018''01/03/2018''01/06/2018';; // or streakRanges(dates) -> accepts an array as well
start: 'Sat Jan 06 2018 00:00:00 GMT-0500'end: nullduration: 1start: 'Mon Jan 01 2018 00:00:00 GMT-0500'end: 'Wed Jan 03 2018 00:00:00 GMT-0500'duration: 3;
Track record returns a list of dates from a specified date into the past with the provided dates marked as
true. This is especially helpful for features where you want to show users a calendar of dates where they completed some task.
Let's get a track record for the days preceeding 1/13/2018.
;const dates ='01/04/2018''01/05/2018''01/11/2018''01/12/2018';// defaults to 7 daysconst length = 10;// defaults to today's dateconst endDate = '01/13/2018';;
'Wed Jan 13 2018 00:00:00 GMT-0400': false'Tue Jan 12 2018 00:00:00 GMT-0400': true'Mon Jan 11 2018 00:00:00 GMT-0400': true'Sun Jan 10 2018 00:00:00 GMT-0400': false'Sat Jan 09 2018 00:00:00 GMT-0400': false'Fri Jan 08 2018 00:00:00 GMT-0400': false'Thu Jan 07 2018 00:00:00 GMT-0400': false'Wed Jan 06 2018 00:00:00 GMT-0400': false'Tue Jan 05 2018 00:00:00 GMT-0400': true'Mon Jan 04 2018 00:00:00 GMT-0400': true
mocha to be installed globally. In the parent of the package, run
npm run test
- Jon Samp
This project is licensed under the MIT License - see the LICENSE.md file for details.