date-streaks
date-streaks copied to clipboard
A possible bug in streakRanges
Firstly, love the library!
I have a dataset with 215 records, the summary data ends up with 77 total sum of the streaks. From what I can understand:
The streakdData function reduces, based on the assumption that summing the streaks will equal the size of the dataset (ie 215).
allDates.splice(0, streak);
https://github.com/jonsamp/date-streaks/blob/master/src/streakRanges.js#L17
Example with 215 records, if you look at the output from the last console, you will notice it never gets into 2021, I believe this is linked to how it keeps slicing at the start, but doesnt have context of days without any type of streak, or a streak of 1.
const data = JSON.parse(
'["2021-03-26T17:56:54.757Z","2021-03-25T22:59:32.550Z","2021-03-24T20:56:56.929Z","2021-03-23T17:47:15.640Z","2021-03-22T11:00:07.874Z","2021-03-21T21:32:11.517Z","2021-03-20T22:11:09.236Z","2021-03-19T22:33:24.557Z","2021-03-18T11:04:14.313Z","2021-03-17T17:40:14.108Z","2021-03-16T13:28:20.475Z","2021-03-15T18:19:18.646Z","2021-03-14T14:41:27.803Z","2021-03-14T14:31:44.871Z","2021-03-11T22:59:13.522Z","2021-03-10T18:54:34.421Z","2021-03-09T22:53:29.000Z","2021-03-08T22:51:24.561Z","2021-03-07T21:54:52.807Z","2021-03-06T22:04:45.958Z","2021-03-05T22:12:06.632Z","2021-03-04T22:56:09.393Z","2021-03-03T09:36:06.324Z","2021-03-02T22:19:45.293Z","2021-02-28T21:41:17.685Z","2021-02-25T22:59:40.413Z","2021-02-24T22:59:51.556Z","2021-02-23T10:42:32.997Z","2021-02-23T10:41:26.128Z","2021-02-23T10:40:21.090Z","2021-02-21T22:27:08.434Z","2021-02-20T14:14:21.558Z","2021-02-19T22:06:43.036Z","2021-02-18T11:22:45.286Z","2021-02-18T11:21:41.158Z","2021-02-17T22:37:04.152Z","2021-02-17T11:15:28.410Z","2021-02-17T11:14:24.937Z","2021-02-16T22:19:37.511Z","2021-02-16T06:32:45.025Z","2021-02-15T22:20:39.368Z","2021-02-14T22:55:24.512Z","2021-02-12T18:15:32.956Z","2021-02-11T21:00:35.725Z","2021-02-10T22:20:30.159Z","2021-02-10T22:19:26.108Z","2021-02-10T22:18:20.637Z","2021-02-09T22:24:28.965Z","2021-02-08T22:15:19.264Z","2021-02-07T07:38:42.870Z","2021-02-07T07:37:38.517Z","2021-02-07T07:36:32.880Z","2021-02-06T09:00:07.221Z","2021-02-05T21:07:19.939Z","2021-02-04T21:34:26.199Z","2021-02-03T22:02:27.313Z","2021-02-03T22:01:22.087Z","2021-02-02T21:49:39.513Z","2021-02-01T21:28:31.736Z","2021-01-30T22:08:34.908Z","2021-01-29T21:50:22.403Z","2021-01-28T22:48:41.895Z","2021-01-26T22:07:47.801Z","2021-01-23T22:39:54.783Z","2021-01-22T22:53:40.066Z","2021-01-21T22:06:55.057Z","2021-01-20T06:47:47.594Z","2021-01-19T21:43:11.414Z","2021-01-17T21:36:43.957Z","2021-01-16T22:06:46.684Z","2021-01-16T09:25:59.242Z","2021-01-15T22:02:33.551Z","2021-01-14T21:52:21.045Z","2021-01-13T06:55:23.643Z","2021-01-12T22:17:30.334Z","2021-01-11T16:02:14.669Z","2021-01-10T22:10:04.404Z","2021-01-10T12:24:50.315Z","2021-01-09T12:50:44.440Z","2021-01-09T12:48:44.479Z","2021-01-08T22:30:37.324Z","2021-01-08T16:18:01.667Z","2021-01-08T06:28:08.161Z","2021-01-06T22:58:28.703Z","2021-01-06T10:53:37.885Z","2021-01-05T21:02:53.208Z","2021-01-05T21:00:19.132Z","2021-01-04T18:50:41.816Z","2021-01-04T11:35:18.645Z","2021-01-03T21:15:43.109Z","2021-01-03T18:50:34.592Z","2021-01-02T16:58:27.147Z","2021-01-02T14:30:32.859Z","2021-01-02T10:37:42.668Z","2021-01-02T10:36:24.759Z","2021-01-01T21:30:49.976Z","2020-12-31T13:50:48.620Z","2020-12-31T13:49:31.098Z","2020-12-31T13:48:23.397Z","2020-12-30T22:43:24.415Z","2020-12-29T21:36:22.291Z","2020-12-29T21:35:16.157Z","2020-12-29T15:56:18.163Z","2020-12-27T21:35:23.428Z","2020-12-27T12:31:49.764Z","2020-12-27T11:58:52.997Z","2020-12-26T13:10:25.310Z","2020-12-26T12:53:53.598Z","2020-12-25T12:13:35.059Z","2020-12-25T12:10:51.962Z","2020-12-25T12:08:49.283Z","2020-12-24T23:32:55.147Z","2020-12-24T14:03:58.830Z","2020-12-24T12:02:58.437Z","2020-12-23T21:05:04.940Z","2020-12-23T12:34:09.344Z","2020-12-23T12:32:17.473Z","2020-12-22T16:23:46.541Z","2020-12-22T12:19:25.762Z","2020-12-21T21:32:41.177Z","2020-12-21T13:46:28.817Z","2020-12-21T13:36:50.570Z","2020-12-20T15:06:00.750Z","2020-12-20T10:56:23.209Z","2020-12-19T20:49:24.225Z","2020-12-19T17:38:55.117Z","2020-12-19T03:09:41.243Z","2020-12-19T02:52:57.149Z","2020-12-18T08:45:04.413Z","2020-12-18T07:38:38.352Z","2020-12-17T07:42:16.327Z","2020-12-16T17:05:04.207Z","2020-12-16T16:44:53.857Z","2020-12-15T17:58:13.178Z","2020-12-15T16:36:58.027Z","2020-12-15T06:21:15.886Z","2020-12-14T22:01:39.320Z","2020-12-14T16:42:46.564Z","2020-12-14T10:43:07.651Z","2020-12-13T15:04:00.017Z","2020-12-12T17:46:22.605Z","2020-12-08T22:53:48.608Z","2020-12-08T13:55:02.729Z","2020-12-07T22:58:41.124Z","2020-12-06T21:40:36.921Z","2020-12-05T16:33:28.742Z","2020-12-05T12:50:39.533Z","2020-12-03T22:50:55.426Z","2020-12-02T22:43:10.268Z","2020-12-01T21:38:44.581Z","2020-11-30T22:20:14.800Z","2020-11-25T22:55:11.713Z","2020-11-24T22:07:28.377Z","2020-11-24T22:06:10.641Z","2020-11-21T22:11:01.282Z","2020-11-19T10:24:32.535Z","2020-11-18T22:24:10.111Z","2020-11-17T23:14:24.611Z","2020-11-16T17:07:38.462Z","2020-11-15T19:14:01.250Z","2020-11-14T21:55:53.236Z","2020-11-14T09:22:01.719Z","2020-11-13T22:01:49.031Z","2020-11-12T21:51:12.315Z","2020-11-11T12:47:29.498Z","2020-11-10T22:42:08.306Z","2020-11-09T22:24:37.598Z","2020-11-08T22:51:09.253Z","2020-11-07T22:53:17.112Z","2020-11-06T11:26:42.798Z","2020-11-05T22:01:31.648Z","2020-11-04T22:50:39.418Z","2020-11-02T21:56:45.954Z","2020-11-01T21:32:15.622Z","2020-10-27T22:36:02.725Z","2020-10-26T22:56:14.927Z","2020-10-25T21:47:39.667Z","2020-10-22T21:04:02.594Z","2020-10-20T23:15:10.074Z","2020-10-20T21:58:41.333Z","2020-10-19T21:51:23.219Z","2020-10-17T11:38:02.622Z","2020-10-16T21:17:55.281Z","2020-10-12T21:53:32.557Z","2020-10-09T17:22:33.548Z","2020-10-08T21:17:04.697Z","2020-10-07T21:55:20.111Z","2020-10-06T06:13:56.575Z","2020-10-05T05:51:29.666Z","2020-10-01T20:13:05.219Z","2020-09-19T12:48:29.872Z","2020-08-30T16:48:50.837Z","2020-08-24T16:50:04.163Z","2020-08-12T18:53:43.226Z","2020-08-12T15:44:53.594Z","2020-08-12T14:06:57.305Z","2020-08-11T20:26:34.908Z","2020-08-11T20:16:40.524Z","2020-08-11T18:19:04.332Z","2020-08-11T16:56:32.809Z","2020-08-10T20:52:24.461Z","2020-08-10T20:47:27.974Z","2020-08-10T19:06:58.622Z","2020-08-10T18:56:24.675Z","2020-08-10T18:45:18.873Z","2020-08-10T18:38:46.677Z","2020-07-23T15:59:16.402Z","2020-07-19T21:51:19.771Z","2020-07-17T13:51:32.430Z","2020-07-16T20:34:50.589Z","2020-07-15T21:16:24.099Z","2020-07-14T19:10:33.819Z","2020-07-14T10:51:25.592Z","2020-07-13T06:28:31.778Z","2020-07-12T14:19:20.780Z"]'
);
console.log(summary(data));
console.log(streakRanges({ dates: data }));
Perhaps the fact my dates might not be unique are not helping the situation.
I can confirm the lack of unique "YYYY-MM-DD" was my issue.
I am now getting correct dates :), the currentStreak is two days behind, but I have not done the activity for today, so its within range :).
Import
import format from "date-fns/format";
let data = JSON.parse(
'["2021-03-26T17:56:54.757Z","2021-03-25T22:59:32.550Z","2021-03-24T20:56:56.929Z","2021-03-23T17:47:15.640Z","2021-03-22T11:00:07.874Z","2021-03-21T21:32:11.517Z","2021-03-20T22:11:09.236Z","2021-03-19T22:33:24.557Z","2021-03-18T11:04:14.313Z","2021-03-17T17:40:14.108Z","2021-03-16T13:28:20.475Z","2021-03-15T18:19:18.646Z","2021-03-14T14:41:27.803Z","2021-03-14T14:31:44.871Z","2021-03-11T22:59:13.522Z","2021-03-10T18:54:34.421Z","2021-03-09T22:53:29.000Z","2021-03-08T22:51:24.561Z","2021-03-07T21:54:52.807Z","2021-03-06T22:04:45.958Z","2021-03-05T22:12:06.632Z","2021-03-04T22:56:09.393Z","2021-03-03T09:36:06.324Z","2021-03-02T22:19:45.293Z","2021-02-28T21:41:17.685Z","2021-02-25T22:59:40.413Z","2021-02-24T22:59:51.556Z","2021-02-23T10:42:32.997Z","2021-02-23T10:41:26.128Z","2021-02-23T10:40:21.090Z","2021-02-21T22:27:08.434Z","2021-02-20T14:14:21.558Z","2021-02-19T22:06:43.036Z","2021-02-18T11:22:45.286Z","2021-02-18T11:21:41.158Z","2021-02-17T22:37:04.152Z","2021-02-17T11:15:28.410Z","2021-02-17T11:14:24.937Z","2021-02-16T22:19:37.511Z","2021-02-16T06:32:45.025Z","2021-02-15T22:20:39.368Z","2021-02-14T22:55:24.512Z","2021-02-12T18:15:32.956Z","2021-02-11T21:00:35.725Z","2021-02-10T22:20:30.159Z","2021-02-10T22:19:26.108Z","2021-02-10T22:18:20.637Z","2021-02-09T22:24:28.965Z","2021-02-08T22:15:19.264Z","2021-02-07T07:38:42.870Z","2021-02-07T07:37:38.517Z","2021-02-07T07:36:32.880Z","2021-02-06T09:00:07.221Z","2021-02-05T21:07:19.939Z","2021-02-04T21:34:26.199Z","2021-02-03T22:02:27.313Z","2021-02-03T22:01:22.087Z","2021-02-02T21:49:39.513Z","2021-02-01T21:28:31.736Z","2021-01-30T22:08:34.908Z","2021-01-29T21:50:22.403Z","2021-01-28T22:48:41.895Z","2021-01-26T22:07:47.801Z","2021-01-23T22:39:54.783Z","2021-01-22T22:53:40.066Z","2021-01-21T22:06:55.057Z","2021-01-20T06:47:47.594Z","2021-01-19T21:43:11.414Z","2021-01-17T21:36:43.957Z","2021-01-16T22:06:46.684Z","2021-01-16T09:25:59.242Z","2021-01-15T22:02:33.551Z","2021-01-14T21:52:21.045Z","2021-01-13T06:55:23.643Z","2021-01-12T22:17:30.334Z","2021-01-11T16:02:14.669Z","2021-01-10T22:10:04.404Z","2021-01-10T12:24:50.315Z","2021-01-09T12:50:44.440Z","2021-01-09T12:48:44.479Z","2021-01-08T22:30:37.324Z","2021-01-08T16:18:01.667Z","2021-01-08T06:28:08.161Z","2021-01-06T22:58:28.703Z","2021-01-06T10:53:37.885Z","2021-01-05T21:02:53.208Z","2021-01-05T21:00:19.132Z","2021-01-04T18:50:41.816Z","2021-01-04T11:35:18.645Z","2021-01-03T21:15:43.109Z","2021-01-03T18:50:34.592Z","2021-01-02T16:58:27.147Z","2021-01-02T14:30:32.859Z","2021-01-02T10:37:42.668Z","2021-01-02T10:36:24.759Z","2021-01-01T21:30:49.976Z","2020-12-31T13:50:48.620Z","2020-12-31T13:49:31.098Z","2020-12-31T13:48:23.397Z","2020-12-30T22:43:24.415Z","2020-12-29T21:36:22.291Z","2020-12-29T21:35:16.157Z","2020-12-29T15:56:18.163Z","2020-12-27T21:35:23.428Z","2020-12-27T12:31:49.764Z","2020-12-27T11:58:52.997Z","2020-12-26T13:10:25.310Z","2020-12-26T12:53:53.598Z","2020-12-25T12:13:35.059Z","2020-12-25T12:10:51.962Z","2020-12-25T12:08:49.283Z","2020-12-24T23:32:55.147Z","2020-12-24T14:03:58.830Z","2020-12-24T12:02:58.437Z","2020-12-23T21:05:04.940Z","2020-12-23T12:34:09.344Z","2020-12-23T12:32:17.473Z","2020-12-22T16:23:46.541Z","2020-12-22T12:19:25.762Z","2020-12-21T21:32:41.177Z","2020-12-21T13:46:28.817Z","2020-12-21T13:36:50.570Z","2020-12-20T15:06:00.750Z","2020-12-20T10:56:23.209Z","2020-12-19T20:49:24.225Z","2020-12-19T17:38:55.117Z","2020-12-19T03:09:41.243Z","2020-12-19T02:52:57.149Z","2020-12-18T08:45:04.413Z","2020-12-18T07:38:38.352Z","2020-12-17T07:42:16.327Z","2020-12-16T17:05:04.207Z","2020-12-16T16:44:53.857Z","2020-12-15T17:58:13.178Z","2020-12-15T16:36:58.027Z","2020-12-15T06:21:15.886Z","2020-12-14T22:01:39.320Z","2020-12-14T16:42:46.564Z","2020-12-14T10:43:07.651Z","2020-12-13T15:04:00.017Z","2020-12-12T17:46:22.605Z","2020-12-08T22:53:48.608Z","2020-12-08T13:55:02.729Z","2020-12-07T22:58:41.124Z","2020-12-06T21:40:36.921Z","2020-12-05T16:33:28.742Z","2020-12-05T12:50:39.533Z","2020-12-03T22:50:55.426Z","2020-12-02T22:43:10.268Z","2020-12-01T21:38:44.581Z","2020-11-30T22:20:14.800Z","2020-11-25T22:55:11.713Z","2020-11-24T22:07:28.377Z","2020-11-24T22:06:10.641Z","2020-11-21T22:11:01.282Z","2020-11-19T10:24:32.535Z","2020-11-18T22:24:10.111Z","2020-11-17T23:14:24.611Z","2020-11-16T17:07:38.462Z","2020-11-15T19:14:01.250Z","2020-11-14T21:55:53.236Z","2020-11-14T09:22:01.719Z","2020-11-13T22:01:49.031Z","2020-11-12T21:51:12.315Z","2020-11-11T12:47:29.498Z","2020-11-10T22:42:08.306Z","2020-11-09T22:24:37.598Z","2020-11-08T22:51:09.253Z","2020-11-07T22:53:17.112Z","2020-11-06T11:26:42.798Z","2020-11-05T22:01:31.648Z","2020-11-04T22:50:39.418Z","2020-11-02T21:56:45.954Z","2020-11-01T21:32:15.622Z","2020-10-27T22:36:02.725Z","2020-10-26T22:56:14.927Z","2020-10-25T21:47:39.667Z","2020-10-22T21:04:02.594Z","2020-10-20T23:15:10.074Z","2020-10-20T21:58:41.333Z","2020-10-19T21:51:23.219Z","2020-10-17T11:38:02.622Z","2020-10-16T21:17:55.281Z","2020-10-12T21:53:32.557Z","2020-10-09T17:22:33.548Z","2020-10-08T21:17:04.697Z","2020-10-07T21:55:20.111Z","2020-10-06T06:13:56.575Z","2020-10-05T05:51:29.666Z","2020-10-01T20:13:05.219Z","2020-09-19T12:48:29.872Z","2020-08-30T16:48:50.837Z","2020-08-24T16:50:04.163Z","2020-08-12T18:53:43.226Z","2020-08-12T15:44:53.594Z","2020-08-12T14:06:57.305Z","2020-08-11T20:26:34.908Z","2020-08-11T20:16:40.524Z","2020-08-11T18:19:04.332Z","2020-08-11T16:56:32.809Z","2020-08-10T20:52:24.461Z","2020-08-10T20:47:27.974Z","2020-08-10T19:06:58.622Z","2020-08-10T18:56:24.675Z","2020-08-10T18:45:18.873Z","2020-08-10T18:38:46.677Z","2020-07-23T15:59:16.402Z","2020-07-19T21:51:19.771Z","2020-07-17T13:51:32.430Z","2020-07-16T20:34:50.589Z","2020-07-15T21:16:24.099Z","2020-07-14T19:10:33.819Z","2020-07-14T10:51:25.592Z","2020-07-13T06:28:31.778Z","2020-07-12T14:19:20.780Z"]'
);
data = data.map((d) => {
return format(new Date(d), "YYYY-MM-DD");
});
data = [...new Set(data)];
console.log(summary(data));
console.log(streakRanges({ dates: data }));