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