feat: Add createdAt and updatedAt to Note entity

This commit is contained in:
Dendy 2025-02-06 15:49:33 +09:00
parent a0beb36a01
commit 230f5f18a1
1 changed files with 15 additions and 3 deletions

View File

@ -12,8 +12,9 @@ class Note
//#[ORM\GeneratedValue] //#[ORM\GeneratedValue]
//#[ORM\Column] //#[ORM\Column]
private int $id; private int $id;
private array $terms = []; private int $mod;
private array $terms = [];
const HIGHLIGHT_PATTERN = '/<span\s+([^>]*)>(.*?)<\/span>/i'; const HIGHLIGHT_PATTERN = '/<span\s+([^>]*)>(.*?)<\/span>/i';
const HIGHLIGHT_ATTR_KANJI = 'style="color: rgb(255, 78, 8);"'; const HIGHLIGHT_ATTR_KANJI = 'style="color: rgb(255, 78, 8);"';
@ -38,7 +39,7 @@ class Note
{ {
$note = new self(); $note = new self();
$note->id = $noteInfo['noteId']; ['noteId' => $note->id, 'mod' => $note->mod] = $noteInfo;
$fields = array_map(fn($x) => $x['value'], $noteInfo['fields']); $fields = array_map(fn($x) => $x['value'], $noteInfo['fields']);
@ -120,6 +121,17 @@ class Note
return $terms; 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 class Term