Added support for user timezones and user browser timezone by default (incomplete) (#13626)

* Added support for user timezones and user browser timezone byt default

* Formatting fixes

* Use the timezone for alert log display

also added validation for the timezone because it's being used in SQL.

* Formatting fixes

* Added return type

* Formatting"

* Update the latency graphs to use the user timezone

* Simplify the web routes config

* Update phpstan to ignore type error

* Fixed up the phpstan config

* Reverse phpstan change

* Re-apply phpstan override

* Remove the option to unset the session timezone

* Formatting fix

* Update outge and event logs to use session timezone

* Fix route for the timezone control

* Made the timezone more dynamic

* Fix a logic error that was stopping the timezone from being set automatically on login

* Prevent getPref from being called twice

* again prevent getPref double call

* getPref double call

* Fixed typo made during merge

* Fixed merge error in phpstan-baseline.neon

* Change spaces to tabs in phpstan-baseline.neon

* Update error count

---------

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
eskyuu
2023-05-09 23:24:48 +08:00
committed by GitHub
parent 56e9fa3742
commit ce0734ff5d
19 changed files with 216 additions and 20 deletions

View File

@@ -58,10 +58,13 @@ class LatencyController implements DeviceTab
public function data(Device $device): array
{
$from = Request::get('dtpickerfrom', Carbon::now()->subDays(2)->format(Config::get('dateformat.byminute')));
$to = Request::get('dtpickerto', Carbon::now()->format(Config::get('dateformat.byminute')));
$from = Request::get('dtpickerfrom', Carbon::now(session('timezone'))->subDays(2)->format(Config::get('dateformat.byminute')));
$to = Request::get('dtpickerto', Carbon::now(session('timezone'))->format(Config::get('dateformat.byminute')));
$perf = $this->fetchPerfData($device, $from, $to);
$dbfrom = Carbon::createFromFormat(Config::get('dateformat.byminute'), $from)->setTimezone(date_default_timezone_get())->format(Config::get('dateformat.byminute'));
$dbto = Carbon::createFromFormat(Config::get('dateformat.byminute'), $to)->setTimezone(date_default_timezone_get())->format(Config::get('dateformat.byminute'));
$perf = $this->fetchPerfData($device, $dbfrom, $dbto);
$duration = $perf && $perf->isNotEmpty()
? abs(strtotime($perf->first()->date) - strtotime($perf->last()->date)) * 1000
@@ -91,7 +94,7 @@ class LatencyController implements DeviceTab
return DB::table('device_perf')
->where('device_id', $device->device_id)
->whereBetween('timestamp', [$from, $to])
->select(DB::raw("DATE_FORMAT(timestamp, '%Y-%m-%d %H:%i') date,xmt,rcv,loss,min,max,avg"))
->selectRaw("DATE_FORMAT(IFNULL(CONVERT_TZ(timestamp, @@global.time_zone, ?), timestamp), '%Y-%m-%d %H:%i') date,xmt,rcv,loss,min,max,avg", [session('timezone')])
->get();
}