laravel-trend
laravel-trend copied to clipboard
[Question / Feature ] Manage timezone
Hi, Thanks for this nice package, Please how could we manage queries timezone if we use per day (hours) option ?
I have the same question - when displaying hourly data over a day, it is off by 2 hours because of different timezone capture.
Hi,
I guess you have the original data in UTC timezone and have to display it with the user/app timezone. The data is correctly aggregated you just have to manipulate the labels.
This is an example to displey the last 72 hours...
You can manipulate the labels like this:
$dataA = Trend::model(ActaAyuntamiento::class)
->between(
start: now()->addHours(-72),
end: now(),
)
->perHour()
->count('*');
return [
'datasets' => [
[
'label' => 'Actas Ayuntamiento',
'data' => $dataA->map(fn (TrendValue $value) => $value->aggregate),
'backgroundColor' => '#797979',
'borderColor' => '#797979',
'stack' => 'actas',
],
],
'labels' => $dataA->map(fn (TrendValue $value) => Carbon::createFromFormat('Y-m-d H:i', $value->date, 'UTC')
->timezone('America/Monterrey')
->format('H:i')),
];
Hope it helps.
Thank you so much @ramnzys :)))