1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-03-23 16:59:53 +01:00

Allow dateTimeBetween to accept DateTime instances

This commit is contained in:
Jordi Boggiano 2012-10-27 11:32:24 +02:00
parent 468dd5b726
commit 83fd81c0c0

View File

@ -79,8 +79,8 @@ class DateTime extends \Faker\Provider\Base
*/
public static function dateTimeBetween($startDate = "-30 years", $endDate = "now")
{
$startTimestamp = strtotime($startDate);
$endTimestamp = strtotime($endDate);
$startTimestamp = $startDate instanceof \DateTime ? $startDate->getTimestamp() : strtotime($startDate);
$endTimestamp = $endDate instanceof \DateTime ? $endDate->getTimestamp() : strtotime($endDate);
$timestamp = mt_rand($startTimestamp, $endTimestamp);
return new \DateTime('@' . $timestamp);