I have an array of dates that I need to group by year, month, week, day, 6 hours, 8 hours, and 1 hour, and then sum the values. Here is an example of the data:
const datesData = [
{ date: "2021-10-17T14:38:45.540Z", value: 2 },
{ date: "2021-09-16T14:36:46.540Z", value: 1 },
{ date: "2021-01-04T14:35:46.540Z", value: 2 },
// more data...
]
I attempted to group the data using Moment.js and Lodash. You can see my code here.
However, when grouping by year, I faced issues with some years like 2018 and 2016 not being displayed in the result:
[
{
"color": "Blue",
"value": 6,
"label": "2021"
},
// more results...
]
Here is the expected output for grouping by year:
[
{
"color": "Blue",
"value": 6,
"label": "2021"
},
// additional results including 2018 and 2016
]