mirror of
https://github.com/flarum/core.git
synced 2025-08-04 23:47:32 +02:00
[statistics] fix: add missing last period to custom date ranges (#3661)
* fix: last node in previous data matches first node of current data * fix: add previous period support for custom periods * test: update to show previous period for custom range
This commit is contained in:
@@ -126,8 +126,15 @@ class ShowStatisticsData implements RequestHandlerInterface
|
||||
|
||||
private function getTimedCounts(Builder $query, string $column, ?DateTime $startDate = null, ?DateTime $endDate = null)
|
||||
{
|
||||
$diff = $startDate && $endDate ? $startDate->diff($endDate) : null;
|
||||
|
||||
if (! isset($startDate)) {
|
||||
$startDate = new DateTime('-365 days');
|
||||
// need -12 months and period before that
|
||||
$startDate = new DateTime('-2 years');
|
||||
} else {
|
||||
// If the start date is custom, we need to include an equal amount beforehand
|
||||
// to show the data for the previous period.
|
||||
$startDate = (new Carbon($startDate))->subtract($diff)->toDateTime();
|
||||
}
|
||||
|
||||
if (! isset($endDate)) {
|
||||
|
Reference in New Issue
Block a user