From d936d73d7e5fe256aedaf3b6a8ef0e0e2a9fb3d1 Mon Sep 17 00:00:00 2001 From: chance garcia Date: Tue, 12 Jul 2016 21:12:26 -0400 Subject: [PATCH] Since DateInterval does not show microseconds, these modifications were made to find the microseconds elapsed for a given result. This allows us to find the microseconds to be used in conjunction with the DateInterval::format. This only finds the elapsed microseconds and no other difference value. --- src/Result.php | 15 +++++++++++++++ src/Workflow/StepAggregator.php | 10 +++++----- tests/ResultTest.php | 10 ++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Result.php b/src/Result.php index dc9e7426..bc0746d6 100644 --- a/src/Result.php +++ b/src/Result.php @@ -11,6 +11,7 @@ */ class Result { + const MICRO_FORMAT = 'd-m-Y H:i:s.u'; /** * Identifier given to the import/export * @@ -143,4 +144,18 @@ public function getExceptions() { return $this->exceptions; } + + /** + * find the elapsed microseconds for the result. This only finds the microsecond difference, use {@link getElapsed()} + * + * @return number + */ + public function getMicroElapsed() + { + $microStart = $this->startTime->format('u'); + $microEnd = $this->endTime->format('u'); + $microDiff = abs($microEnd - $microStart); + + return $microDiff; + } } diff --git a/src/Workflow/StepAggregator.php b/src/Workflow/StepAggregator.php index afdddf82..9182d38f 100644 --- a/src/Workflow/StepAggregator.php +++ b/src/Workflow/StepAggregator.php @@ -73,7 +73,7 @@ public function __construct(Reader $reader, $name = null) /** * Add a step to the current workflow * - * @param Step $step + * @param Step $step * @param integer|null $priority * * @return $this @@ -107,9 +107,9 @@ public function addWriter(Writer $writer) */ public function process() { - $count = 0; + $count = 0; $exceptions = new \SplObjectStorage(); - $startTime = new \DateTime; + $startTime = new \DateTime(date_format(new \DateTime(), 'd-m-Y H:i:s') . substr((string)microtime(), 1, 8)); foreach ($this->writers as $writer) { $writer->prepare(); @@ -145,7 +145,7 @@ public function process() foreach ($this->writers as $writer) { $writer->writeItem($item); } - } catch(Exception $e) { + } catch (Exception $e) { if (!$this->skipItemOnFailure) { throw $e; } @@ -161,7 +161,7 @@ public function process() $writer->finish(); } - return new Result($this->name, $startTime, new \DateTime, $count, $exceptions); + return new Result($this->name, $startTime, new \DateTime(date_format(new \DateTime(), 'd-m-Y H:i:s') . substr((string)microtime(), 1, 8)), $count, $exceptions); } /** diff --git a/tests/ResultTest.php b/tests/ResultTest.php index 73274eaa..9f6f4d4b 100644 --- a/tests/ResultTest.php +++ b/tests/ResultTest.php @@ -46,6 +46,16 @@ public function testDates() $this->assertInstanceOf('DateInterval', $result->getElapsed()); } + public function testMicroElapsed() + { + $startDate = new \DateTime('2016-07-12 20:51:42.805421'); + $endDate = new \DateTime('2016-07-12 20:51:42.841276'); + $microElapsed = abs($endDate->format('u') - $startDate->format('u')); + + $result = new Result('export', $startDate, $endDate, 10, new \SplObjectStorage()); + $this->assertSame($microElapsed, $result->getMicroElapsed()); + } + public function testHasErrorsReturnsTrueIfAnyExceptions() { $exceptions = new \SplObjectStorage();