fix dates in project API (#1451)
This commit is contained in:
@@ -202,7 +202,9 @@ class ProjectController extends BaseApiController
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ProjectApiEditForm::class, $project);
|
||||
$form = $this->createForm(ProjectApiEditForm::class, $project, [
|
||||
'date_format' => self::DATE_FORMAT,
|
||||
]);
|
||||
|
||||
$form->submit($request->request->all());
|
||||
|
||||
@@ -264,7 +266,9 @@ class ProjectController extends BaseApiController
|
||||
$event = new ProjectMetaDefinitionEvent($project);
|
||||
$this->dispatcher->dispatch($event);
|
||||
|
||||
$form = $this->createForm(ProjectApiEditForm::class, $project);
|
||||
$form = $this->createForm(ProjectApiEditForm::class, $project, [
|
||||
'date_format' => self::DATE_FORMAT,
|
||||
]);
|
||||
|
||||
$form->setData($project);
|
||||
$form->submit($request->request->all(), false);
|
||||
|
||||
@@ -44,6 +44,12 @@ class ProjectEditForm extends AbstractType
|
||||
}
|
||||
}
|
||||
|
||||
$dateTimeOptions = [];
|
||||
// primarily for API usage, where we cannot use a user/locale specific format
|
||||
if (null !== $options['date_format']) {
|
||||
$dateTimeOptions['format'] = $options['date_format'];
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('name', TextType::class, [
|
||||
'label' => 'label.name',
|
||||
@@ -59,18 +65,18 @@ class ProjectEditForm extends AbstractType
|
||||
'label' => 'label.orderNumber',
|
||||
'required' => false,
|
||||
])
|
||||
->add('orderDate', DateTimePickerType::class, [
|
||||
->add('orderDate', DateTimePickerType::class, array_merge($dateTimeOptions, [
|
||||
'label' => 'label.orderDate',
|
||||
'required' => false,
|
||||
])
|
||||
->add('start', DateTimePickerType::class, [
|
||||
]))
|
||||
->add('start', DateTimePickerType::class, array_merge($dateTimeOptions, [
|
||||
'label' => 'label.project_start',
|
||||
'required' => false,
|
||||
])
|
||||
->add('end', DateTimePickerType::class, [
|
||||
]))
|
||||
->add('end', DateTimePickerType::class, array_merge($dateTimeOptions, [
|
||||
'label' => 'label.project_end',
|
||||
'required' => false,
|
||||
])
|
||||
]))
|
||||
->add('customer', CustomerType::class, [
|
||||
'query_builder' => function (CustomerRepository $repo) use ($builder, $customer) {
|
||||
$query = new CustomerFormTypeQuery($customer);
|
||||
@@ -98,6 +104,7 @@ class ProjectEditForm extends AbstractType
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_project_edit',
|
||||
'currency' => Customer::DEFAULT_CURRENCY,
|
||||
'date_format' => null,
|
||||
'include_budget' => false,
|
||||
'create_more' => false,
|
||||
'attr' => [
|
||||
|
||||
@@ -130,6 +130,9 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
'name' => 'foo',
|
||||
'customer' => 1,
|
||||
'visible' => true,
|
||||
'orderDate' => '2018-02-08T13:02:54',
|
||||
'start' => '2019-02-01T19:32:17',
|
||||
'end' => '2020-02-08T21:11:42',
|
||||
];
|
||||
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
@@ -138,6 +141,9 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
$this->assertIsArray($result);
|
||||
$this->assertStructure($result);
|
||||
$this->assertNotEmpty($result['id']);
|
||||
self::assertEquals('2018-02-08T13:02:54+0000', $result['orderDate']);
|
||||
self::assertEquals('2019-02-01T19:32:17+0000', $result['start']);
|
||||
self::assertEquals('2020-02-08T21:11:42+0000', $result['end']);
|
||||
}
|
||||
|
||||
public function testPostActionWithInvalidUser()
|
||||
|
||||
@@ -102,10 +102,8 @@ class DailyWorkingTimeChartTest extends TestCase
|
||||
{
|
||||
$repository = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->onlyMethods(['getDailyData'])->getMock();
|
||||
$repository->expects($this->once())->method('getDailyData')->willReturnCallback(function ($begin, $end, $user) {
|
||||
$today = (new \DateTime());
|
||||
|
||||
return [
|
||||
['year' => $today->format('Y'), 'month' => $today->format('n'), 'day' => $today->format('j'), 'rate' => 13.75, 'duration' => 1234]
|
||||
['year' => $begin->format('Y'), 'month' => $begin->format('n'), 'day' => $begin->format('j'), 'rate' => 13.75, 'duration' => 1234]
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user