# fakerpress/0.8.0/src/functions/date.php

FakerPress, version 0.8.0. 35 lines.

- Page: https://pluginprobe.com/plugins/fakerpress/0.8.0/code/src/functions/date.php
- Raw: https://pluginprobe.com/plugins/fakerpress/0.8.0/raw/src/functions/date.php
- Modified: 2025-05-18T23:58:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fakerpress/0.8.0/code/src/functions/date.php#L10-L20`.

```php
<?php
/**
 * Date Functions
 *
 * @package FakerPress
 * 
 * @since TBD
 */

namespace FakerPress;

use FakerPress\ThirdParty\Cake\Chronos\Chronos;
use WP_Error;

/**
 * Creates a chronos date without throwing an error.
 *
 * @since TBD
 *
 * @param string $raw_date The date to create.
 * @param string $tz The timezone to create the date in.
 *
 * @return Chronos|WP_Error
 */
function chronos( $raw_date, $tz = null ) {
	// Unfortunately there is not such solution to this problem, we need to try and catch with DateTime.
	try {
		$date = new Chronos( $raw_date, $tz );
	} catch ( \Exception $e ) {
		$date = new WP_Error( 'fakerpress-date-error', null, [ 'error' => $e ] );
	}

	return $date;
}

```
