Skip to content

Commit

Permalink
Add datetime method
Browse files Browse the repository at this point in the history
  • Loading branch information
maillotf committed Oct 27, 2020
1 parent e960809 commit 8819f4f
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/Objects/Right.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,41 @@ class Right extends AbstractArdObject
* @var int
*/
private $creationdate;

/**
*
* @var \DateTime
*/
private $creationdatetime = null;

/**
*
* @var int
*/
private $modificationdate;

/**
*
* @var \DateTime
*/
private $modificationdatetime = null;

/**
*
* @var DateTimeZone
*/
private $datetimezone;

public function init()
{
parent::init();
$this->setDatetimezone('Europe/Paris');
}

public function __construct($datetimezone = 'Europe/Paris')
{
$this->datetimezone = new \DateTimeZone($datetimezone);
}

public function setUid(int $uid): Right
{
Expand Down Expand Up @@ -116,6 +145,17 @@ public function getCreationdate(): int
{
return $this->creationdate;
}

public function getCreationdatetime(): ?\DateTime
{
if ($this->creationdatetime == null)
{
$this->creationdatetime = new \DateTime();
$this->creationdatetime->setTimezone($this->datetimezone);
$this->creationdatetime->setTimestamp($this->getCreationdate());
}
return ($this->creationdatetime);
}

public function setModificationdate(int $modificationdate): Right
{
Expand All @@ -127,5 +167,27 @@ public function getModificationdate(): int
{
return $this->modificationdate;
}

public function getModificationdatetime(): ?\DateTime
{
if ($this->modificationdatetime == null)
{
$this->modificationdatetime = new \DateTime();
$this->modificationdatetime->setTimezone($this->datetimezone);
$this->modificationdatetime->setTimestamp($this->getModificationdate());
}
return ($this->modificationdatetime);
}

public function setDatetimezone(string $datetimezone)
{
$this->datetimezone = new \DateTimeZone($datetimezone);
return ($this);
}

public function getDatetimezone(): \DateTimeZone
{
return ($this->datetimezone);
}

}

0 comments on commit 8819f4f

Please sign in to comment.