- $link = [
- 'title' => ! empty($input['title']) ? $input['title'] : $input['url'],
- 'url' => $input['url'],
- 'description' => ! empty($input['description']) ? $input['description'] : '',
- 'tags' => ! empty($input['tags']) ? implode(' ', $input['tags']) : '',
- 'private' => $private,
- 'created' => new \DateTime(),
- ];
- return $link;
+ $bookmark->setTitle(! empty($input['title']) ? $input['title'] : '');
+ $bookmark->setUrl($url);
+ $bookmark->setDescription(! empty($input['description']) ? $input['description'] : '');
+ $bookmark->setTags(! empty($input['tags']) ? $input['tags'] : []);
+ $bookmark->setPrivate($private);
+
+ $created = \DateTime::createFromFormat(\DateTime::ATOM, $input['created'] ?? '');
+ if ($created instanceof \DateTimeInterface) {
+ $bookmark->setCreated($created);
+ }
+ $updated = \DateTime::createFromFormat(\DateTime::ATOM, $input['updated'] ?? '');
+ if ($updated instanceof \DateTimeInterface) {
+ $bookmark->setUpdated($updated);
+ }
+
+ return $bookmark;