2021-04-27 10:21:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
2021-04-27 12:51:21 +02:00
|
|
|
use DateInterval;
|
2021-04-27 10:41:21 +02:00
|
|
|
use DateTime;
|
2021-04-27 10:21:21 +02:00
|
|
|
use DateTimeInterface;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
trait TimeStampableTrait {
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"})
|
|
|
|
*/
|
|
|
|
private $createdAt;
|
|
|
|
|
|
|
|
public function getCreatedAt(): ?DateTimeInterface {
|
|
|
|
return $this->createdAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCreatedAt( DateTimeInterface $createdAt ): self {
|
|
|
|
$this->createdAt = $createdAt;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:22:16 +02:00
|
|
|
public function getCreatedAtAsString(): string {
|
|
|
|
return $this->createdAt->format( 'c' );
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:41:21 +02:00
|
|
|
|
|
|
|
public function addDaysToDate( DateTime $date, int $days ) {
|
|
|
|
|
2021-04-27 12:51:21 +02:00
|
|
|
return $date->add( new DateInterval( 'P' . $days . 'D' ) );
|
2021-04-27 10:41:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-27 10:21:21 +02:00
|
|
|
}
|