PluginProbe
WooCommerce / 11.1.0-beta.1
WooCommerce v11.1.0-beta.1
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / src / Utilities / TimeUtil.php
TimeUtil.php
49 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Automattic\WooCommerce\Utilities;
4
5 use \DateTime;
6 use \DateTimeZone;
7 use \Exception;
8
9 /**
10 * Class with date and time utilities.
11 */
12 class TimeUtil {
13
14 /**
15 * Instance of a DateTimeZone object representing UTC.
16 *
17 * @var DateTimeZone
18 */
19 private static DateTimeZone $utc_date_time_zone;
20
21 /**
22 * Class constructor.
23 */
24 public function __construct() {
25 self::$utc_date_time_zone = new DateTimeZone( 'UTC' );
26 }
27
28 /**
29 * Get the instance of the DateTimeZone object representing UTC.
30 *
31 * @return DateTimeZone DateTimeZone object representing UTC.
32 */
33 public static function get_utc_date_time_zone(): DateTimeZone {
34 return self::$utc_date_time_zone;
35 }
36
37 /**
38 * Check if a string represents a valid date in a given format.
39 *
40 * @param string $date The date string to check.
41 * @param string $format The format to verify the date string against.
42 * @return bool True if $date represents a valid date/time according to $format, false otherwise.
43 */
44 public static function is_valid_date( string $date, string $format = 'Y-m-d H:i:s' ): bool {
45 $d = DateTime::createFromFormat( $format, $date );
46 return $d && $d->format( $format ) === $date;
47 }
48 }
49