diff --git a/lib/Textmaster/Model/Document.php b/lib/Textmaster/Model/Document.php index 42e3feb..e039774 100644 --- a/lib/Textmaster/Model/Document.php +++ b/lib/Textmaster/Model/Document.php @@ -238,6 +238,42 @@ public function setCustomData($customData, $key = null) return $this->setProperty('custom_data', $customData); } + /** + * {@inheritdoc} + */ + public function getCreatedAt() + { + $data = $this->getProperty('created_at'); + + return $this->parseFullDate($data); + } + + /** + * {@inheritdoc} + */ + public function getUpdatedAt() + { + $data = $this->getProperty('updated_at'); + + return $this->parseFullDate($data); + } + + /** + * Parse Textmaster date + * + * @param array $data + * + * @return \DateTime|null + */ + private function parseFullDate($data) + { + if (null !== $data && isset($data['full'])) { + return new \DateTime($data['full']); + } + + return null; + } + /** * {@inheritdoc} */ diff --git a/lib/Textmaster/Model/DocumentInterface.php b/lib/Textmaster/Model/DocumentInterface.php index 8837747..defa335 100644 --- a/lib/Textmaster/Model/DocumentInterface.php +++ b/lib/Textmaster/Model/DocumentInterface.php @@ -170,6 +170,20 @@ public function getCustomData($key = null); */ public function setCustomData($customData, $key = null); + /** + * Get create date + * + * @return \DateTime|null + */ + public function getCreatedAt(); + + /** + * Get update date + * + * @return \DateTime|null + */ + public function getUpdatedAt(); + /** * Complete the document. * diff --git a/test/Textmaster/Unit/Model/DocumentTest.php b/test/Textmaster/Unit/Model/DocumentTest.php index 40b9c75..13a9120 100644 --- a/test/Textmaster/Unit/Model/DocumentTest.php +++ b/test/Textmaster/Unit/Model/DocumentTest.php @@ -132,6 +132,18 @@ public function shouldCreateFromValues() 'original_content' => 'Text to translate.', 'instructions' => 'Translating instructions.', 'project_id' => $projectId, + 'created_at' => [ + 'day' => 9, + 'month' => 6, + 'year' => 2016, + 'full' => '2016-06-09 10:37:40 UTC', + ], + 'updated_at' => [ + 'day' => 10, + 'month' => 6, + 'year' => 2016, + 'full' => '2016-06-10 15:37:40 UTC', + ], ); $document = new Document($this->clientMock, $values); @@ -141,6 +153,14 @@ public function shouldCreateFromValues() $this->assertSame(DocumentInterface::STATUS_IN_CREATION, $document->getStatus()); $this->assertSame('Text to translate.', $document->getOriginalContent()); $this->assertSame('Translating instructions.', $document->getInstructions()); + + $expectedDate = new \DateTime('2016-06-09 10:37:40 UTC'); + $this->assertEquals($expectedDate, $document->getCreatedAt()); + $this->assertEquals('20160609 10:37:40', $document->getCreatedAt()->format('Ymd H:i:s')); + + $expectedDate = new \DateTime('2016-06-10 15:37:40 UTC'); + $this->assertEquals($expectedDate, $document->getUpdatedAt()); + $this->assertEquals('20160610 15:37:40', $document->getUpdatedAt()->format('Ymd H:i:s')); } /**