| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copy of WC3.0 WC_DateTime class |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace WPO\WC\PostNL\Compatibility; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 9 |
|
| 10 |
if ( ! class_exists( '\\WPO\\WC\\PostNL\\Compatibility\\WC_DateTime' ) ) : |
| 11 |
|
| 12 |
|
| 13 |
/** |
| 14 |
* WC Wrapper for PHP DateTime. |
| 15 |
* |
| 16 |
* @class WC_DateTime |
| 17 |
* @since 3.0.0 |
| 18 |
* @package WooCommerce/Classes |
| 19 |
* @category Class |
| 20 |
* @author WooThemes |
| 21 |
*/ |
| 22 |
class WC_DateTime extends \DateTime { |
| 23 |
|
| 24 |
/** |
| 25 |
* Output an ISO 8601 date string in local timezone. |
| 26 |
* |
| 27 |
* @since 3.0.0 |
| 28 |
* @return string |
| 29 |
*/ |
| 30 |
public function __toString() { |
| 31 |
return $this->format( DATE_ATOM ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Missing in PHP 5.2. |
| 36 |
* |
| 37 |
* @since 3.0.0 |
| 38 |
* @return int |
| 39 |
*/ |
| 40 |
public function getTimestamp() { |
| 41 |
return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get the timestamp with the WordPress timezone offset added or subtracted. |
| 46 |
* |
| 47 |
* @since 3.0.0 |
| 48 |
* @return int |
| 49 |
*/ |
| 50 |
public function getOffsetTimestamp() { |
| 51 |
return $this->getTimestamp() + $this->getOffset(); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Format a date based on the offset timestamp. |
| 56 |
* |
| 57 |
* @since 3.0.0 |
| 58 |
* @param string $format |
| 59 |
* @return string |
| 60 |
*/ |
| 61 |
public function date( $format ) { |
| 62 |
return gmdate( $format, $this->getOffsetTimestamp() ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Return a localised date based on offset timestamp. Wrapper for date_i18n function. |
| 67 |
* |
| 68 |
* @since 3.0.0 |
| 69 |
* @param string $format |
| 70 |
* @return string |
| 71 |
*/ |
| 72 |
public function date_i18n( $format = 'Y-m-d' ) { |
| 73 |
return date_i18n( $format, $this->getOffsetTimestamp() ); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
endif; // Class exists check |