fix datetime modify to now (#3511)
This commit is contained in:
@@ -118,7 +118,7 @@ class QuickEntryController extends AbstractController
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$beginTime = $this->configuration->getTimesheetDefaultBeginTime();
|
$beginTime = $factory->createDateTime($this->configuration->getTimesheetDefaultBeginTime())->format('H:i:s');
|
||||||
|
|
||||||
// fill all rows and columns to make sure we do not have missing records
|
// fill all rows and columns to make sure we do not have missing records
|
||||||
/** @var QuickEntryModel[] $models */
|
/** @var QuickEntryModel[] $models */
|
||||||
|
|||||||
@@ -55,7 +55,11 @@ final class DurationFixedBeginMode implements TrackingModeInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$newBegin = clone $timesheet->getBegin();
|
$newBegin = clone $timesheet->getBegin();
|
||||||
$newBegin->modify($this->configuration->getTimesheetDefaultBeginTime());
|
|
||||||
|
// this prevents the problem that "now" is being ignored in modify()
|
||||||
|
$beginTime = (new DateTime($this->configuration->getTimesheetDefaultBeginTime(), $newBegin->getTimezone()))->format('H:i:s');
|
||||||
|
$newBegin->modify($beginTime);
|
||||||
|
|
||||||
$timesheet->setBegin($newBegin);
|
$timesheet->setBegin($newBegin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,12 @@ final class DurationOnlyMode extends AbstractTrackingMode
|
|||||||
}
|
}
|
||||||
|
|
||||||
$newBegin = clone $timesheet->getBegin();
|
$newBegin = clone $timesheet->getBegin();
|
||||||
$newBegin->modify($this->configuration->getTimesheetDefaultBeginTime());
|
|
||||||
|
// this prevents the problem that "now" is being ignored in modify()
|
||||||
|
$beginTime = $this->configuration->getTimesheetDefaultBeginTime();
|
||||||
|
$beginTime = (new DateTime($this->configuration->getTimesheetDefaultBeginTime(), $newBegin->getTimezone()))->format('H:i:s');
|
||||||
|
$newBegin->modify($beginTime);
|
||||||
|
|
||||||
$timesheet->setBegin($newBegin);
|
$timesheet->setBegin($newBegin);
|
||||||
|
|
||||||
parent::create($timesheet, $request);
|
parent::create($timesheet, $request);
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
*/
|
*/
|
||||||
class DurationFixedBeginModeTest extends TestCase
|
class DurationFixedBeginModeTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function createSut()
|
protected function createSut($default = '13:47')
|
||||||
{
|
{
|
||||||
$loader = new TestConfigLoader([]);
|
$loader = new TestConfigLoader([]);
|
||||||
$configuration = new SystemConfiguration($loader, ['timesheet' => ['default_begin' => '13:47']]);
|
$configuration = new SystemConfiguration($loader, ['timesheet' => ['default_begin' => $default]]);
|
||||||
|
|
||||||
return new DurationFixedBeginMode($configuration);
|
return new DurationFixedBeginMode($configuration);
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,18 @@ class DurationFixedBeginModeTest extends TestCase
|
|||||||
self::assertEquals('duration_fixed_begin', $sut->getId());
|
self::assertEquals('duration_fixed_begin', $sut->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNow()
|
||||||
|
{
|
||||||
|
$seconds = (new \DateTime())->getTimestamp();
|
||||||
|
$timesheet = new Timesheet();
|
||||||
|
$timesheet->setBegin(new \DateTime('18:50:32'));
|
||||||
|
$mode = $this->createSut('now');
|
||||||
|
$mode->create($timesheet);
|
||||||
|
$diff = $timesheet->getBegin()->getTimestamp() - $seconds;
|
||||||
|
// amount of seconds doesn't really matter, it must only be near "now"
|
||||||
|
self::assertLessThanOrEqual(2, $diff);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
$timesheet = new Timesheet();
|
$timesheet = new Timesheet();
|
||||||
|
|||||||
@@ -25,14 +25,26 @@ class DurationOnlyModeTest extends AbstractTrackingModeTest
|
|||||||
self::assertEquals('13:45:37', $timesheet->getBegin()->format('H:i:s'));
|
self::assertEquals('13:45:37', $timesheet->getBegin()->format('H:i:s'));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createSut()
|
protected function createSut($default = '13:45:37')
|
||||||
{
|
{
|
||||||
$loader = new TestConfigLoader([]);
|
$loader = new TestConfigLoader([]);
|
||||||
$configuration = new SystemConfiguration($loader, ['timesheet' => ['default_begin' => '13:45:37']]);
|
$configuration = new SystemConfiguration($loader, ['timesheet' => ['default_begin' => $default]]);
|
||||||
|
|
||||||
return new DurationOnlyMode($configuration);
|
return new DurationOnlyMode($configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNow()
|
||||||
|
{
|
||||||
|
$seconds = (new \DateTime())->getTimestamp();
|
||||||
|
$timesheet = new Timesheet();
|
||||||
|
$timesheet->setBegin(new \DateTime('18:50:32'));
|
||||||
|
$mode = $this->createSut('now');
|
||||||
|
$mode->create($timesheet);
|
||||||
|
$diff = $timesheet->getBegin()->getTimestamp() - $seconds;
|
||||||
|
// amount of seconds doesn't really matter, it must only be near "now"
|
||||||
|
self::assertLessThanOrEqual(2, $diff);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDefaultValues()
|
public function testDefaultValues()
|
||||||
{
|
{
|
||||||
$sut = $this->createSut();
|
$sut = $this->createSut();
|
||||||
|
|||||||
Reference in New Issue
Block a user