WC_DateTime

WC Wrapper for PHP DateTime.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-datetime.php  
  1. class WC_DateTime extends DateTime { 
  2.  
  3. /** 
  4. * UTC Offset if needed. 
  5. * @var integer 
  6. */ 
  7. protected $utc_offset = 0; 
  8.  
  9. /** 
  10. * Output an ISO 8601 date string in local timezone. 
  11. * @since 3.0.0 
  12. * @return string 
  13. */ 
  14. public function __toString() { 
  15. return $this->format( DATE_ATOM ); 
  16.  
  17. /** 
  18. * Set UTC offset. 
  19. */ 
  20. public function set_utc_offset( $offset ) { 
  21. $this->utc_offset = intval( $offset ); 
  22.  
  23. /** 
  24. * getOffset. 
  25. */ 
  26. public function getOffset() { 
  27. if ( $this->utc_offset ) { 
  28. return $this->utc_offset; 
  29. } else { 
  30. return parent::getOffset(); 
  31.  
  32. /** 
  33. * Set timezone. 
  34. * @param DateTimeZone $timezone 
  35. */ 
  36. public function setTimezone( $timezone ) { 
  37. $this->utc_offset = 0; 
  38. return parent::setTimezone( $timezone ); 
  39.  
  40. /** 
  41. * Missing in PHP 5.2. 
  42. * @since 3.0.0 
  43. * @return int 
  44. */ 
  45. public function getTimestamp() { 
  46. return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' ); 
  47.  
  48. /** 
  49. * Get the timestamp with the WordPress timezone offset added or subtracted. 
  50. * @since 3.0.0 
  51. * @return int 
  52. */ 
  53. public function getOffsetTimestamp() { 
  54. return $this->getTimestamp() + $this->getOffset(); 
  55.  
  56. /** 
  57. * Format a date based on the offset timestamp. 
  58. * @since 3.0.0 
  59. * @param string $format 
  60. * @return string 
  61. */ 
  62. public function date( $format ) { 
  63. return gmdate( $format, $this->getOffsetTimestamp() ); 
  64.  
  65. /** 
  66. * Return a localised date based on offset timestamp. Wrapper for date_i18n function. 
  67. * @since 3.0.0 
  68. * @param string $format 
  69. * @return string 
  70. */ 
  71. public function date_i18n( $format = 'Y-m-d' ) { 
  72. return date_i18n( $format, $this->getOffsetTimestamp() );