From 11a818a314833d2bfa5eeeb48fb022ea03b26d03 Mon Sep 17 00:00:00 2001 From: Mat Fish Date: Fri, 26 Nov 2021 13:19:49 +0200 Subject: [PATCH] randomize post date --- CHANGELOG.md | 4 ++++ src/services/FakerService.php | 7 +++++++ src/services/SeedingService.php | 1 + 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59867af..0464147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Blogify +## 1.0.8 - 2021-11-26 +### Changed +- Seeding: Randomize post date + ## 1.0.7 - 2021-11-24 ### Fixed - Fixed author query diff --git a/src/services/FakerService.php b/src/services/FakerService.php index 787c61c..00a761a 100644 --- a/src/services/FakerService.php +++ b/src/services/FakerService.php @@ -94,6 +94,13 @@ public static function arrayElements($arr, $n) }, $keys); } + public static function date() { + $max = time(); + $min = $max - 3600 * 24 * 365 * 2; // two years ago + + return date("Y-m-d H:i:s", mt_rand($min, $max)); + } + private static function words($n) { $res = []; diff --git a/src/services/SeedingService.php b/src/services/SeedingService.php index 2ecae84..d5871f3 100644 --- a/src/services/SeedingService.php +++ b/src/services/SeedingService.php @@ -32,6 +32,7 @@ public function seed() 'typeId' => $entryType->id, 'authorId' => FakerService::arrayElement($this->getUsers()), 'title' => FakerService::sentence(), + 'postDate'=>FakerService::date() ]); $entry->setFieldValue(Handles::POST_IMAGE, [FakerService::arrayElement($images)]);