| 1 |
<?php |
| 2 |
/** |
| 3 |
* Date Functions |
| 4 |
* |
| 5 |
* @package FakerPress |
| 6 |
* |
| 7 |
* @since TBD |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace FakerPress; |
| 11 |
|
| 12 |
use FakerPress\ThirdParty\Cake\Chronos\Chronos; |
| 13 |
use WP_Error; |
| 14 |
|
| 15 |
/** |
| 16 |
* Creates a chronos date without throwing an error. |
| 17 |
* |
| 18 |
* @since TBD |
| 19 |
* |
| 20 |
* @param string $raw_date The date to create. |
| 21 |
* @param string $tz The timezone to create the date in. |
| 22 |
* |
| 23 |
* @return Chronos|WP_Error |
| 24 |
*/ |
| 25 |
function chronos( $raw_date, $tz = null ) { |
| 26 |
// Unfortunately there is not such solution to this problem, we need to try and catch with DateTime. |
| 27 |
try { |
| 28 |
$date = new Chronos( $raw_date, $tz ); |
| 29 |
} catch ( \Exception $e ) { |
| 30 |
$date = new WP_Error( 'fakerpress-date-error', null, [ 'error' => $e ] ); |
| 31 |
} |
| 32 |
|
| 33 |
return $date; |
| 34 |
} |
| 35 |
|