Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| DateTime | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| generateDateTime | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Utils\RnG |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Utils\RnG; |
| 16 | |
| 17 | /** |
| 18 | * DateTime generator. |
| 19 | * |
| 20 | * @package phpOMS\Utils\RnG |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | class DateTime |
| 26 | { |
| 27 | /** |
| 28 | * Get a random \DateTime. |
| 29 | * |
| 30 | * @param \DateTime $start Start date |
| 31 | * @param \DateTime $end End date |
| 32 | * |
| 33 | * @return \DateTime |
| 34 | * |
| 35 | * @since 1.0.0 |
| 36 | */ |
| 37 | public static function generateDateTime(\DateTime $start, \DateTime $end) : \DateTime |
| 38 | { |
| 39 | $rng = new \DateTime(); |
| 40 | |
| 41 | return $rng->setTimestamp(\mt_rand($start->getTimestamp(), $end->getTimestamp())); |
| 42 | } |
| 43 | } |