I have data in my database in UTC time format in this format (pseudo):
[
{
"date": "Date: 2020-02-12T08:00:00+0000"
"productsSold": {
0: 122,
1: 130,
2: 90,
...
}
}
]
So in this example on the 12 of February, 122 products were sold in an onlineshop between midnight and 1 o'clock (UTC time); 130 products have been sold between 1am and 2am, etc.
I want to display in the frontend the products that have been sold during the last week - aggregated on a daily basis (e.g. on Monday 1200 products were sold; on Tuesday 1500 products, etc.). This should be done in dependency of the users time zone.
Now I see two possibilities:
- The frontend does a HTTP request with the user's time zone. The backend does the calculation, i.e. aggregates the products sold depending on the requested time zone.
- The frontend always performs the same request. The backend returns detailed, non-aggregated data of the last eight days. The frontend does the transformation and calculation process.
What would be your approach and why?