From 21280eb4bcac113fcb86546ffff6307e58b282b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 21 Oct 2023 17:25:07 +0200 Subject: [PATCH] Normalise custom post dates --- .../src/Framework/Actions/CreatesNewMarkdownPostFile.php | 2 +- .../tests/Unit/CreatesNewMarkdownPostFileTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewMarkdownPostFile.php b/packages/framework/src/Framework/Actions/CreatesNewMarkdownPostFile.php index ac4c621ef20..a2285f6db6a 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewMarkdownPostFile.php +++ b/packages/framework/src/Framework/Actions/CreatesNewMarkdownPostFile.php @@ -45,7 +45,7 @@ public function __construct(string $title, ?string $description, ?string $catego $this->author = $author ?? 'default'; $this->customContent = $customContent; - $this->date = $date ?? Carbon::now()->format('Y-m-d H:i'); + $this->date = Carbon::make($date ?? Carbon::now())->format('Y-m-d H:i'); $this->identifier = Str::slug($title); } diff --git a/packages/framework/tests/Unit/CreatesNewMarkdownPostFileTest.php b/packages/framework/tests/Unit/CreatesNewMarkdownPostFileTest.php index adbe063062f..6cc69a48669 100644 --- a/packages/framework/tests/Unit/CreatesNewMarkdownPostFileTest.php +++ b/packages/framework/tests/Unit/CreatesNewMarkdownPostFileTest.php @@ -96,4 +96,13 @@ public function testSaveWithCustomContent() unlink($path); } + + public function testCustomDateNormalisation() + { + $action = new CreatesNewMarkdownPostFile('Example Post', null, null, null, 'Jan 1 2024 8am'); + + $array = $action->toArray(); + + $this->assertSame('2024-01-01 08:00', $array['date']); + } }