PluginProbe
FakerPress / 0.7.2
FakerPress v0.7.2
0.9.2 trunk 0.1.0 0.1.1 0.1.2 0.1.3 0.5.2 0.5.3 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.7.0 0.7.1 0.7.2 0.8.0 0.9.0 0.9.1
fakerpress / src / functions / date.php

date.php in FakerPress 0.7.2, at src/functions/date.php

35 lines 699 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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