cleanup global context (#1943)

This commit is contained in:
Kevin Papst
2020-09-08 20:35:14 +02:00
committed by GitHub
parent 217960de60
commit e2a742b5c1
9 changed files with 54 additions and 63 deletions

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\User;
use App\Timesheet\DateTimeFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
@@ -22,4 +23,13 @@ abstract class BaseApiController extends AbstractController
{
public const DATE_FORMAT = DateTimeType::HTML5_FORMAT;
public const DATE_FORMAT_PHP = 'Y-m-d\TH:i:s';
protected function getDateTimeFactory(?User $user = null): DateTimeFactory
{
if (null === $user) {
$user = $this->getUser();
}
return new DateTimeFactory(new \DateTimeZone($user->getTimezone()));
}
}