2025-09-04 15:06:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BookStack\Util;
|
|
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2025-09-04 16:11:35 +01:00
|
|
|
use Carbon\CarbonInterface;
|
2025-09-04 15:06:58 +01:00
|
|
|
|
|
|
|
|
class DateFormatter
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
protected string $displayTimezone,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-04 16:11:35 +01:00
|
|
|
public function absolute(Carbon $date): string
|
2025-09-04 15:06:58 +01:00
|
|
|
{
|
|
|
|
|
$withDisplayTimezone = $date->clone()->setTimezone($this->displayTimezone);
|
|
|
|
|
|
|
|
|
|
return $withDisplayTimezone->format('Y-m-d H:i:s T');
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-04 16:11:35 +01:00
|
|
|
public function relative(Carbon $date, bool $includeSuffix = true): string
|
2025-09-04 15:06:58 +01:00
|
|
|
{
|
2025-09-04 16:11:35 +01:00
|
|
|
return $date->diffForHumans(null, $includeSuffix ? null : CarbonInterface::DIFF_ABSOLUTE);
|
2025-09-04 15:06:58 +01:00
|
|
|
}
|
|
|
|
|
}
|