From 230f5f18a1404e6c38eeccfda1f20e91c66e19e7 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Thu, 6 Feb 2025 15:49:33 +0900 Subject: [PATCH] feat: Add createdAt and updatedAt to Note entity --- src/Entity/Note.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Entity/Note.php b/src/Entity/Note.php index a06c22a..3d902bf 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -12,8 +12,9 @@ class Note //#[ORM\GeneratedValue] //#[ORM\Column] - private int $id; - private array $terms = []; + private int $id; + private int $mod; + private array $terms = []; const HIGHLIGHT_PATTERN = '/]*)>(.*?)<\/span>/i'; const HIGHLIGHT_ATTR_KANJI = 'style="color: rgb(255, 78, 8);"'; @@ -38,7 +39,7 @@ class Note { $note = new self(); - $note->id = $noteInfo['noteId']; + ['noteId' => $note->id, 'mod' => $note->mod] = $noteInfo; $fields = array_map(fn($x) => $x['value'], $noteInfo['fields']); @@ -120,6 +121,17 @@ class Note return $terms; } + + public function getCreatedAt(): \DateTimeImmutable + { + $timestamp = ceil($this->id / 1000); + return \DateTimeImmutable::createFromFormat('U', $timestamp); + } + + public function getUpdatedAt(): \DateTimeImmutable + { + return \DateTimeImmutable::createFromFormat('U', $this->mod); + } } class Term