Skip to content

Commit

Permalink
Modified time is always set
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed May 22, 2024
1 parent 2781b54 commit 5764866
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/Entity/Traits/Timestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ trait Timestamp
#[ORM\Column(type: 'datetimetz', options: ['default' => 'CURRENT_TIMESTAMP'])]
protected readonly DateTime $created;

#[ORM\Column(type: 'datetimetz', nullable: true)]
protected ?DateTime $modified = null;
#[ORM\Column(type: 'datetimetz')]
protected DateTime $modified;


public function setCreated(DateTimeInterface $created): void
Expand All @@ -32,26 +32,21 @@ public function getCreated(): DateTime
}


public function setModified(?DateTimeInterface $modified): void
public function setModified(DateTimeInterface $modified): void
{
if (!is_null($modified)) {
$modified = DateTime::createFromInterface($modified);
}

$this->modified = $modified ?? new DateTime;
$this->modified = DateTime::createFromInterface($modified);
}


public function getModified(): ?DateTime
public function getModified(): DateTime
{
if (!$this->modified) {
return null;
}

return clone $this->modified;
}


/**
* @deprecated
*/
public function getTimestamp(): DateTime
{
return clone ($this->modified ?: $this->created);
Expand All @@ -62,6 +57,7 @@ public function getTimestamp(): DateTime
public function onCreated(): void
{
$this->created ??= new DateTime;
$this->modified = new DateTime;
}


Expand Down

0 comments on commit 5764866

Please sign in to comment.