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