* оптимизация доставки контента до клиента * переписал запросы выборок * убрал из подсчета переведенных * добавил сохранение метрикам для вывода в дашборд
90 lines
1.9 KiB
PHP
90 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Collection;
|
|
|
|
readonly class DateRange
|
|
{
|
|
public function __construct(
|
|
public Carbon $startDate,
|
|
public Carbon $endDate,
|
|
public string $startDateRaw,
|
|
public string $endDateRaw,
|
|
public bool $isOneDay
|
|
) {}
|
|
|
|
/**
|
|
* Получить начало диапазона в Carbon
|
|
*/
|
|
public function start(): Carbon
|
|
{
|
|
return $this->startDate;
|
|
}
|
|
|
|
/**
|
|
* Получить конец диапазона в Carbon
|
|
*/
|
|
public function end(): Carbon
|
|
{
|
|
return $this->endDate;
|
|
}
|
|
|
|
/**
|
|
* Получить начало диапазона в SQL формате
|
|
*/
|
|
public function startSql(): string
|
|
{
|
|
return $this->startDate->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
/**
|
|
* Получить конец диапазона в SQL формате
|
|
*/
|
|
public function endSql(): string
|
|
{
|
|
return $this->endDate->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
/**
|
|
* Получить начало диапазона как timestamp
|
|
*/
|
|
public function startTimestamp(): int
|
|
{
|
|
return $this->startDate->getTimestampMs();
|
|
}
|
|
|
|
/**
|
|
* Получить конец диапазона как timestamp
|
|
*/
|
|
public function endTimestamp(): int
|
|
{
|
|
return $this->endDate->getTimestampMs();
|
|
}
|
|
|
|
/**
|
|
* Проверить, является ли дата сегодняшней
|
|
*/
|
|
public function isEndDateToday(): bool
|
|
{
|
|
return $this->endDate->isToday();
|
|
}
|
|
|
|
/**
|
|
* Получить диапазон дней
|
|
*/
|
|
public function getDaysRange(): Collection
|
|
{
|
|
$days = collect();
|
|
$current = $this->startDate->copy();
|
|
|
|
while ($current->lte($this->endDate)) {
|
|
$days->push($current->copy());
|
|
$current->addDay();
|
|
}
|
|
|
|
return $days;
|
|
}
|
|
}
|