I have below array of objects,
[{
a: 1,
created_on: '2021-04-23 10:00:01',
}, {
b: 1,
created_on: '2021-04-24 09:03:01',
}, {
b: 1,
created_on: '2021-04-24 13:03:01',
}]
First, I need to group by with date ignoring times.
So,
{
"2021-04-23": [{
a: 1,
created_on: '2021-04-23 10:00:01',
}],
....
}
If it were a date like created_on: '2021-04-23'
, I could use lodash/groupBy
.
I still could use it but now it involves some condition to be applied to convert those created_on
into date format.
Further, I also need to group by those each grouped by date result as such that their created_on
falls within a time interval.
"SALES_SLOTS": [
{
"slot": "00:00-04:00"
},
{
"slot": "04:00-08:00"
},
{
"slot":"08:00-12:00"
},
{
"slot":"12:00-16:00"
},
{
"slot":"16:00-20:00"
},
{
"slot":"20:00-24:00"
}
],
So, if created_on: '2021-04-23 10:00:01'
, it should come in the group,
{
"08:00-12:00": [{
a: 1,
created_on: '2021-04-23 10:00:01',
}]
}
So, first results should be grouped by date from created on and then elements in each groups should be further group by defined time slots.
I suppose, if I could use group by condition, I could achieve the desired result.