I have items in my list, and the items have a field that shows the date the item was created.

and I need to group them based on the "compression" that the user gives. Possible values ββare Day , Week , Month and Year .
If the user selects Day compression, I need to group my elements so that the elements created on the same day are grouped. In my example above, on the same day only points 1 and 2 are created. The rest are also groups, but they will only have one element, because only one element is created at a time.
{{item1, item2}, {item3}, {item4}, {item5}, {item6}, {item7}}
If the user selects Week :
{{item1, item2, item3, item4}, {item5}, {item6}, {item7}}
If the user selects Month :
{{item1, item2, item3, item4, item5}, {item6}, {item7}}
If the user selects Year :
{{item1, item2, item3, item4, item5, item6}, {item7}}
After creating the groups, the date of the elements is not important. I mean, the key can be anything if groups are created.
In the case of using Map , I thought the following keys:
Day = day of the year
Week = week of the year
Month = month of the year
Year = year
What would be the best solution to this problem? I couldnβt even start it, I canβt think of a solution other than iteration.