fix timezone problems in timesheet forms (#555)

This commit is contained in:
Kevin Papst
2019-02-13 21:37:54 +01:00
committed by GitHub
parent 2c6f57c7ce
commit ef33233624
23 changed files with 461 additions and 61 deletions

View File

@@ -20,6 +20,7 @@ use App\Form\Type\YesNoType;
use App\Repository\ActivityRepository;
use App\Repository\CustomerRepository;
use App\Repository\ProjectRepository;
use App\Timesheet\UserDateTimeFactory;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
@@ -48,15 +49,22 @@ class TimesheetEditForm extends AbstractType
*/
private $durationOnly = false;
/**
* @var UserDateTimeFactory
*/
protected $dateTime;
/**
* @param CustomerRepository $customer
* @param ProjectRepository $project
* @param UserDateTimeFactory $dateTime
* @param bool $durationOnly
*/
public function __construct(CustomerRepository $customer, ProjectRepository $project, bool $durationOnly)
public function __construct(CustomerRepository $customer, ProjectRepository $project, UserDateTimeFactory $dateTime, bool $durationOnly)
{
$this->customers = $customer;
$this->projects = $project;
$this->dateTime = $dateTime;
$this->durationOnly = $durationOnly;
}
@@ -70,6 +78,7 @@ class TimesheetEditForm extends AbstractType
$customer = null;
$currency = false;
$end = null;
$begin = null;
if (isset($options['data'])) {
/** @var Timesheet $entry */
@@ -87,12 +96,21 @@ class TimesheetEditForm extends AbstractType
$currency = $customer->getCurrency();
}
$begin = $entry->getBegin();
$end = $entry->getEnd();
}
$timezone = $this->dateTime->getTimezone()->getName();
if (null !== $begin) {
$timezone = $begin->getTimezone()->getName();
}
if (null === $end || !$options['duration_only']) {
$builder->add('begin', DateTimePickerType::class, [
'label' => 'label.begin',
'model_timezone' => $timezone,
'view_timezone' => $timezone,
]);
}
@@ -102,7 +120,9 @@ class TimesheetEditForm extends AbstractType
]);
} else {
$builder->add('end', DateTimePickerType::class, [
'label' => 'label.end',
'label' => 'label.begin',
'model_timezone' => $timezone,
'view_timezone' => $timezone,
'required' => false,
]);
}
@@ -135,7 +155,10 @@ class TimesheetEditForm extends AbstractType
}
$builder
->add('project', ProjectType::class, array_merge($projectOptions, [
->add(
'project',
ProjectType::class,
array_merge($projectOptions, [
'placeholder' => '',
'activity_enabled' => true,
// documentation is for NelmioApiDocBundle

View File

@@ -9,6 +9,7 @@
namespace App\Form\Type;
use App\Timesheet\UserDateTimeFactory;
use App\Utils\LocaleSettings;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
@@ -26,11 +27,18 @@ class DatePickerType extends AbstractType
protected $localeSettings;
/**
* @param LocaleSettings $localeSettings
* @var UserDateTimeFactory
*/
public function __construct(LocaleSettings $localeSettings)
protected $dateTime;
/**
* @param LocaleSettings $localeSettings
* @param UserDateTimeFactory $dateTime
*/
public function __construct(LocaleSettings $localeSettings, UserDateTimeFactory $dateTime)
{
$this->localeSettings = $localeSettings;
$this->dateTime = $dateTime;
}
/**
@@ -40,12 +48,15 @@ class DatePickerType extends AbstractType
{
$pickerFormat = $this->localeSettings->getDatePickerFormat();
$dateFormat = $this->localeSettings->getDateTypeFormat();
$timezone = $this->dateTime->getTimezone()->getName();
$resolver->setDefaults([
'widget' => 'single_text',
'html5' => false,
'format' => $dateFormat,
'format_picker' => $pickerFormat,
'model_timezone' => $timezone,
'view_timezone' => $timezone,
]);
$resolver->setDefault('attr', function (Options $options) {

View File

@@ -9,6 +9,7 @@
namespace App\Form\Type;
use App\Timesheet\UserDateTimeFactory;
use App\Utils\LocaleSettings;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
@@ -25,12 +26,18 @@ class DateTimePickerType extends AbstractType
*/
protected $localeSettings;
/**
* @var UserDateTimeFactory
*/
protected $dateTime;
/**
* @param LocaleSettings $localeSettings
*/
public function __construct(LocaleSettings $localeSettings)
public function __construct(LocaleSettings $localeSettings, UserDateTimeFactory $dateTime)
{
$this->localeSettings = $localeSettings;
$this->dateTime = $dateTime;
}
/**
@@ -40,6 +47,7 @@ class DateTimePickerType extends AbstractType
{
$dateTimePicker = $this->localeSettings->getDateTimePickerFormat();
$dateTimeFormat = $this->localeSettings->getDateTimeTypeFormat();
$timezone = $this->dateTime->getTimezone()->getName();
$resolver->setDefaults([
'label' => 'label.begin',
@@ -48,6 +56,8 @@ class DateTimePickerType extends AbstractType
'format' => $dateTimeFormat,
'format_picker' => $dateTimePicker,
'with_seconds' => false,
'model_timezone' => $timezone,
'view_timezone' => $timezone,
]);
$resolver->setDefault('attr', function (Options $options) {