diff --git a/genug_user/view/index.php b/genug_user/view/index.php
index 80d63e1..dc34aa0 100644
--- a/genug_user/view/index.php
+++ b/genug_user/view/index.php
@@ -7,7 +7,7 @@
= $genug->requestedPage->title ?>
-
+
- PageGroup: = $genug->requestedPage->group; ?>
groups->fetchOrNull($genug->requestedPage->group); ?>
diff --git a/src/Lib/ValueObject/DateTimeTrait.php b/src/Lib/AbstractDateTime.php
similarity index 63%
rename from src/Lib/ValueObject/DateTimeTrait.php
rename to src/Lib/AbstractDateTime.php
index 40b640b..f8c2d5f 100644
--- a/src/Lib/ValueObject/DateTimeTrait.php
+++ b/src/Lib/AbstractDateTime.php
@@ -11,37 +11,29 @@
* License: MIT License
*/
-namespace genug\Lib\ValueObject;
+namespace genug\Lib;
-use DateTime;
+use DateTimeImmutable;
use InvalidArgumentException;
-
-use function trim;
+use Stringable;
/**
*
* @author David Ringsdorf http://davidringsdorf.de
* @license MIT License
*/
-trait DateTimeTrait
+abstract class AbstractDateTime extends DateTimeImmutable implements Stringable
{
- protected readonly DateTime $dateTime;
-
public function __construct(string $dateTime)
{
if ('' === trim($dateTime)) {
throw new InvalidArgumentException('`$dateTime` is empty or consists of white space. Use `\'now\'` to use the current date and time.');
}
- $this->dateTime = new DateTime($dateTime);
- }
-
- public function format(string $format): string
- {
- return $this->dateTime->format($format);
+ parent::__construct($dateTime);
}
public function __toString(): string
{
- return $this->dateTime->format('c');
+ return $this->format('c');
}
}
diff --git a/src/Page/DateInterface.php b/src/Page/AbstractDateTime.php
similarity index 70%
rename from src/Page/DateInterface.php
rename to src/Page/AbstractDateTime.php
index 56ee17d..ff9e31d 100644
--- a/src/Page/DateInterface.php
+++ b/src/Page/AbstractDateTime.php
@@ -13,14 +13,13 @@
namespace genug\Page;
-use Stringable;
+use genug\Lib\AbstractDateTime as LibAbstractDateTime;
/**
*
* @author David Ringsdorf http://davidringsdorf.de
* @license MIT License
*/
-interface DateInterface extends Stringable
+abstract class AbstractDateTime extends LibAbstractDateTime
{
- public function format(string $format): string;
}
diff --git a/src/Page/Date.php b/src/Page/DateTime.php
similarity index 75%
rename from src/Page/Date.php
rename to src/Page/DateTime.php
index f7ba08f..1800cda 100644
--- a/src/Page/Date.php
+++ b/src/Page/DateTime.php
@@ -18,7 +18,6 @@
* @author David Ringsdorf http://davidringsdorf.de
* @license MIT License
*/
-final class Date implements DateInterface
+final class DateTime extends AbstractDateTime
{
- use \genug\Lib\ValueObject\DateTimeTrait;
}
diff --git a/src/Page/Entity.php b/src/Page/Entity.php
index 7028ebc..40970f0 100644
--- a/src/Page/Entity.php
+++ b/src/Page/Entity.php
@@ -24,7 +24,7 @@ public function __construct(
public readonly AbstractId $id,
public readonly ?AbstractGroup $group,
public readonly ?TitleInterface $title,
- public readonly ?DateInterface $date,
+ public readonly ?AbstractDateTime $dateTime,
public readonly ?ContentInterface $content
) {
}
diff --git a/src/Page/Repository.php b/src/Page/Repository.php
index f48aac8..7c0d233 100644
--- a/src/Page/Repository.php
+++ b/src/Page/Repository.php
@@ -209,7 +209,7 @@ protected function _parseFrontMatterString(string $str): array
return new Title($fm['title']);
})();
- $date = (function () use ($_data, $idString, $logger): ?Date {
+ $dateTime = (function () use ($_data, $idString, $logger): ?DateTime {
$fm = $_data->frontMatter();
if (! isset($fm['date'])) {
$logger->debug(
@@ -217,14 +217,14 @@ protected function _parseFrontMatterString(string $str): array
);
return null;
}
- return new Date($fm['date']);
+ return new DateTime($fm['date']);
})();
$entity = new Entity(
new Id($idString),
$group,
$title,
- $date,
+ $dateTime,
new Content($_data->content())
);