| @@ 210-234 (lines=25) @@ | ||
| 207 | * @param bool $convert_to_utc |
|
| 208 | * @return string RFC3339 datetime |
|
| 209 | */ |
|
| 210 | protected function format_datetime( $timestamp, $convert_to_utc = false ) { |
|
| 211 | if ( $convert_to_utc ) { |
|
| 212 | $timezone = new DateTimeZone( wc_timezone_string() ); |
|
| 213 | } else { |
|
| 214 | $timezone = new DateTimeZone( 'UTC' ); |
|
| 215 | } |
|
| 216 | ||
| 217 | try { |
|
| 218 | if ( is_numeric( $timestamp ) ) { |
|
| 219 | $date = new DateTime( "@{$timestamp}" ); |
|
| 220 | } else { |
|
| 221 | $date = new DateTime( $timestamp, $timezone ); |
|
| 222 | } |
|
| 223 | ||
| 224 | // convert to UTC by adjusting the time based on the offset of the site's timezone |
|
| 225 | if ( $convert_to_utc ) { |
|
| 226 | $date->modify( -1 * $date->getOffset() . ' seconds' ); |
|
| 227 | } |
|
| 228 | ||
| 229 | } catch ( Exception $e ) { |
|
| 230 | $date = new DateTime( '@0' ); |
|
| 231 | } |
|
| 232 | ||
| 233 | return $date->format( 'Y-m-d\TH:i:s\Z' ); |
|
| 234 | } |
|
| 235 | ||
| 236 | /** |
|
| 237 | * Get formatter object based on supplied arguments. |
|
| @@ 668-695 (lines=28) @@ | ||
| 665 | * @param bool $convert_to_utc |
|
| 666 | * @return string RFC3339 datetime |
|
| 667 | */ |
|
| 668 | public function format_datetime( $timestamp, $convert_to_utc = false ) { |
|
| 669 | ||
| 670 | if ( $convert_to_utc ) { |
|
| 671 | $timezone = new DateTimeZone( wc_timezone_string() ); |
|
| 672 | } else { |
|
| 673 | $timezone = new DateTimeZone( 'UTC' ); |
|
| 674 | } |
|
| 675 | ||
| 676 | try { |
|
| 677 | ||
| 678 | if ( is_numeric( $timestamp ) ) { |
|
| 679 | $date = new DateTime( "@{$timestamp}" ); |
|
| 680 | } else { |
|
| 681 | $date = new DateTime( $timestamp, $timezone ); |
|
| 682 | } |
|
| 683 | ||
| 684 | // convert to UTC by adjusting the time based on the offset of the site's timezone |
|
| 685 | if ( $convert_to_utc ) { |
|
| 686 | $date->modify( -1 * $date->getOffset() . ' seconds' ); |
|
| 687 | } |
|
| 688 | ||
| 689 | } catch ( Exception $e ) { |
|
| 690 | ||
| 691 | $date = new DateTime( '@0' ); |
|
| 692 | } |
|
| 693 | ||
| 694 | return $date->format( 'Y-m-d\TH:i:s\Z' ); |
|
| 695 | } |
|
| 696 | ||
| 697 | /** |
|
| 698 | * Extract headers from a PHP-style $_SERVER array |
|
| @@ 705-732 (lines=28) @@ | ||
| 702 | * @param bool $convert_to_utc |
|
| 703 | * @return string RFC3339 datetime |
|
| 704 | */ |
|
| 705 | public function format_datetime( $timestamp, $convert_to_utc = false ) { |
|
| 706 | ||
| 707 | if ( $convert_to_utc ) { |
|
| 708 | $timezone = new DateTimeZone( wc_timezone_string() ); |
|
| 709 | } else { |
|
| 710 | $timezone = new DateTimeZone( 'UTC' ); |
|
| 711 | } |
|
| 712 | ||
| 713 | try { |
|
| 714 | ||
| 715 | if ( is_numeric( $timestamp ) ) { |
|
| 716 | $date = new DateTime( "@{$timestamp}" ); |
|
| 717 | } else { |
|
| 718 | $date = new DateTime( $timestamp, $timezone ); |
|
| 719 | } |
|
| 720 | ||
| 721 | // convert to UTC by adjusting the time based on the offset of the site's timezone |
|
| 722 | if ( $convert_to_utc ) { |
|
| 723 | $date->modify( -1 * $date->getOffset() . ' seconds' ); |
|
| 724 | } |
|
| 725 | ||
| 726 | } catch ( Exception $e ) { |
|
| 727 | ||
| 728 | $date = new DateTime( '@0' ); |
|
| 729 | } |
|
| 730 | ||
| 731 | return $date->format( 'Y-m-d\TH:i:s\Z' ); |
|
| 732 | } |
|
| 733 | ||
| 734 | /** |
|
| 735 | * Extract headers from a PHP-style $_SERVER array |
|
| @@ 711-738 (lines=28) @@ | ||
| 708 | * @param bool $convert_to_utc |
|
| 709 | * @return string RFC3339 datetime |
|
| 710 | */ |
|
| 711 | public function format_datetime( $timestamp, $convert_to_utc = false ) { |
|
| 712 | ||
| 713 | if ( $convert_to_utc ) { |
|
| 714 | $timezone = new DateTimeZone( wc_timezone_string() ); |
|
| 715 | } else { |
|
| 716 | $timezone = new DateTimeZone( 'UTC' ); |
|
| 717 | } |
|
| 718 | ||
| 719 | try { |
|
| 720 | ||
| 721 | if ( is_numeric( $timestamp ) ) { |
|
| 722 | $date = new DateTime( "@{$timestamp}" ); |
|
| 723 | } else { |
|
| 724 | $date = new DateTime( $timestamp, $timezone ); |
|
| 725 | } |
|
| 726 | ||
| 727 | // convert to UTC by adjusting the time based on the offset of the site's timezone |
|
| 728 | if ( $convert_to_utc ) { |
|
| 729 | $date->modify( -1 * $date->getOffset() . ' seconds' ); |
|
| 730 | } |
|
| 731 | ||
| 732 | } catch ( Exception $e ) { |
|
| 733 | ||
| 734 | $date = new DateTime( '@0' ); |
|
| 735 | } |
|
| 736 | ||
| 737 | return $date->format( 'Y-m-d\TH:i:s\Z' ); |
|
| 738 | } |
|
| 739 | ||
| 740 | /** |
|
| 741 | * Extract headers from a PHP-style $_SERVER array |
|