Skip to content

Commit

Permalink
randomize post date
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Nov 26, 2021
1 parent 2892e4a commit 11a818a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/services/FakerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
1 change: 1 addition & 0 deletions src/services/SeedingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
Expand Down

0 comments on commit 11a818a

Please sign in to comment.