mirror of
https://github.com/flarum/core.git
synced 2025-08-04 07:27:39 +02:00
Clean up some variable/method names
This commit is contained in:
@@ -41,9 +41,9 @@ System.register('flarum/statistics/components/StatisticsWidget', ['flarum/compon
|
|||||||
// reset to the first hour of the day, and then convert back into UTC time.
|
// reset to the first hour of the day, and then convert back into UTC time.
|
||||||
// We'll be working with seconds rather than milliseconds throughout too.
|
// We'll be working with seconds rather than milliseconds throughout too.
|
||||||
var today = new Date();
|
var today = new Date();
|
||||||
today.setTime(today.getTime() + app.data.statistics.utcOffset * 1000);
|
today.setTime(today.getTime() + app.data.statistics.timezoneOffset * 1000);
|
||||||
today.setUTCHours(0, 0, 0, 0);
|
today.setUTCHours(0, 0, 0, 0);
|
||||||
today.setTime(today.getTime() - app.data.statistics.utcOffset * 1000);
|
today.setTime(today.getTime() - app.data.statistics.timezoneOffset * 1000);
|
||||||
today = today / 1000;
|
today = today / 1000;
|
||||||
|
|
||||||
this.entities = ['users', 'discussions', 'posts'];
|
this.entities = ['users', 'discussions', 'posts'];
|
||||||
@@ -143,7 +143,7 @@ System.register('flarum/statistics/components/StatisticsWidget', ['flarum/compon
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var offset = app.data.statistics.utcOffset;
|
var offset = app.data.statistics.timezoneOffset;
|
||||||
var period = this.periods[this.selectedPeriod];
|
var period = this.periods[this.selectedPeriod];
|
||||||
var periodLength = period.end - period.start;
|
var periodLength = period.end - period.start;
|
||||||
var labels = [];
|
var labels = [];
|
||||||
|
@@ -24,9 +24,9 @@ export default class StatisticsWidget extends DashboardWidget {
|
|||||||
// reset to the first hour of the day, and then convert back into UTC time.
|
// reset to the first hour of the day, and then convert back into UTC time.
|
||||||
// We'll be working with seconds rather than milliseconds throughout too.
|
// We'll be working with seconds rather than milliseconds throughout too.
|
||||||
let today = new Date();
|
let today = new Date();
|
||||||
today.setTime(today.getTime() + app.data.statistics.utcOffset * 1000);
|
today.setTime(today.getTime() + app.data.statistics.timezoneOffset * 1000);
|
||||||
today.setUTCHours(0, 0, 0, 0);
|
today.setUTCHours(0, 0, 0, 0);
|
||||||
today.setTime(today.getTime() - app.data.statistics.utcOffset * 1000);
|
today.setTime(today.getTime() - app.data.statistics.timezoneOffset * 1000);
|
||||||
today = today / 1000;
|
today = today / 1000;
|
||||||
|
|
||||||
this.entities = ['users', 'discussions', 'posts'];
|
this.entities = ['users', 'discussions', 'posts'];
|
||||||
@@ -99,7 +99,7 @@ export default class StatisticsWidget extends DashboardWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const offset = app.data.statistics.utcOffset;
|
const offset = app.data.statistics.timezoneOffset;
|
||||||
const period = this.periods[this.selectedPeriod];
|
const period = this.periods[this.selectedPeriod];
|
||||||
const periodLength = period.end - period.start;
|
const periodLength = period.end - period.start;
|
||||||
const labels = [];
|
const labels = [];
|
||||||
|
@@ -84,8 +84,8 @@ class AddStatisticsData
|
|||||||
$results = $query
|
$results = $query
|
||||||
->selectRaw(
|
->selectRaw(
|
||||||
'DATE_FORMAT(
|
'DATE_FORMAT(
|
||||||
@date := DATE_ADD('.$column.', INTERVAL ? SECOND), -- correct for timezone
|
@date := DATE_ADD('.$column.', INTERVAL ? SECOND), -- convert to user timezone
|
||||||
IF(@date > ?, \'%Y-%m-%dT%H:00:00\', \'%Y-%m-%dT00:00:00\') -- if within the last 48 hours, group by hour
|
IF(@date > ?, \'%Y-%m-%d %H:00:00\', \'%Y-%m-%d\') -- if within the last 48 hours, group by hour
|
||||||
) as time_group',
|
) as time_group',
|
||||||
[$offset, new DateTime('-48 hours')]
|
[$offset, new DateTime('-48 hours')]
|
||||||
)
|
)
|
||||||
@@ -94,13 +94,14 @@ class AddStatisticsData
|
|||||||
->groupBy('time_group')
|
->groupBy('time_group')
|
||||||
->lists('count', 'time_group');
|
->lists('count', 'time_group');
|
||||||
|
|
||||||
// Now that we have the aggregated statistics, convert each point in
|
// Now that we have the aggregated statistics, convert each time group
|
||||||
// time into a UNIX timestamp .
|
// into a UNIX timestamp.
|
||||||
$displayTimezone = $this->getDisplayTimezone();
|
$userTimezone = $this->getUserTimezone();
|
||||||
|
|
||||||
$timed = [];
|
$timed = [];
|
||||||
|
|
||||||
$results->each(function ($count, $time) use (&$timed, $displayTimezone) {
|
$results->each(function ($count, $time) use (&$timed, $userTimezone) {
|
||||||
$time = new DateTime($time, $displayTimezone);
|
$time = new DateTime($time, $userTimezone);
|
||||||
$timed[$time->getTimestamp()] = $count;
|
$timed[$time->getTimestamp()] = $count;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,19 +110,14 @@ class AddStatisticsData
|
|||||||
|
|
||||||
private function getTimezoneOffset()
|
private function getTimezoneOffset()
|
||||||
{
|
{
|
||||||
|
$now = new DateTime;
|
||||||
|
|
||||||
$dataTimezone = new DateTimeZone(date_default_timezone_get());
|
$dataTimezone = new DateTimeZone(date_default_timezone_get());
|
||||||
|
|
||||||
return $this->getDisplayTimezone()->getOffset(new DateTime('now', $dataTimezone));
|
return $this->getUserTimezone()->getOffset($now) - $dataTimezone->getOffset($now);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getUTCOffset()
|
private function getUserTimezone()
|
||||||
{
|
|
||||||
$utcTimezone = new DateTimeZone('UTC');
|
|
||||||
|
|
||||||
return $this->getDisplayTimezone()->getOffset(new DateTime('now', $utcTimezone));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getDisplayTimezone()
|
|
||||||
{
|
{
|
||||||
return new DateTimeZone($this->settings->get('flarum-statistics.timezone', date_default_timezone_get()));
|
return new DateTimeZone($this->settings->get('flarum-statistics.timezone', date_default_timezone_get()));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user