apply users timezone to toolbar queries (#716)

This commit is contained in:
Kevin Papst
2019-04-22 16:21:22 +02:00
committed by GitHub
parent 46cb021260
commit 215d4fc8bf
11 changed files with 69 additions and 81 deletions

View File

@@ -10,6 +10,7 @@
namespace App\Form\Type;
use App\Form\Model\DateRange;
use App\Timesheet\UserDateTimeFactory;
use App\Utils\LocaleSettings;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
@@ -30,13 +31,19 @@ class DateRangeType extends AbstractType
* @var LocaleSettings
*/
protected $localeSettings;
/**
* @var UserDateTimeFactory
*/
protected $dateFactory;
/**
* @param LocaleSettings $localeSettings
* @param UserDateTimeFactory $dateTime
*/
public function __construct(LocaleSettings $localeSettings)
public function __construct(LocaleSettings $localeSettings, UserDateTimeFactory $dateTime)
{
$this->localeSettings = $localeSettings;
$this->dateFactory = $dateTime;
}
/**
@@ -164,13 +171,13 @@ class DateRangeType extends AbstractType
throw new TransformationFailedException('Invalid date range given');
}
$begin = \DateTime::createFromFormat($formatDate, $values[0]);
$begin = \DateTime::createFromFormat($formatDate, $values[0], $this->dateFactory->getTimezone());
if ($begin === false) {
throw new TransformationFailedException('Invalid begin date given');
}
$range->setBegin($begin);
$end = \DateTime::createFromFormat($formatDate, $values[1]);
$end = \DateTime::createFromFormat($formatDate, $values[1], $this->dateFactory->getTimezone());
if ($end === false) {
throw new TransformationFailedException('Invalid end date given');
}