Changeset 40114 for branches/4.7/src/wp-includes/rest-api.php
- Timestamp:
- 02/24/2017 09:58:07 PM (8 years ago)
- Location:
- branches/4.7
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/src/wp-includes/rest-api.php
r40079 r40114 781 781 782 782 /** 783 * Retrieves a local date with its GMTequivalent, in MySQL datetime format.783 * Parses a date into both its local and UTC equivalent, in MySQL datetime format. 784 784 * 785 785 * @since 4.4.0 … … 787 787 * @see rest_parse_date() 788 788 * 789 * @param string $date 790 * @param bool $ force_utc Whether a UTC timestamp should be forced. Default false.789 * @param string $date RFC3339 timestamp. 790 * @param bool $is_utc Whether the provided date should be interpreted as UTC. Default false. 791 791 * @return array|null Local and UTC datetime strings, in MySQL datetime format (Y-m-d H:i:s), 792 792 * null on failure. 793 793 */ 794 function rest_get_date_with_gmt( $date, $force_utc = false ) { 795 $date = rest_parse_date( $date, $force_utc ); 794 function rest_get_date_with_gmt( $date, $is_utc = false ) { 795 // Whether or not the original date actually has a timezone string 796 // changes the way we need to do timezone conversion. Store this info 797 // before parsing the date, and use it later. 798 $has_timezone = preg_match( '#(Z|[+-]\d{2}(:\d{2})?)$#', $date ); 799 800 $date = rest_parse_date( $date ); 796 801 797 802 if ( empty( $date ) ) { … … 799 804 } 800 805 801 $utc = date( 'Y-m-d H:i:s', $date ); 802 $local = get_date_from_gmt( $utc ); 806 // At this point $date could either be a local date (if we were passed a 807 // *local* date without a timezone offset) or a UTC date (otherwise). 808 // Timezone conversion needs to be handled differently between these two 809 // cases. 810 if ( ! $is_utc && ! $has_timezone ) { 811 $local = date( 'Y-m-d H:i:s', $date ); 812 $utc = get_gmt_from_date( $local ); 813 } else { 814 $utc = date( 'Y-m-d H:i:s', $date ); 815 $local = get_date_from_gmt( $utc ); 816 } 803 817 804 818 return array( $local, $utc );
Note: See TracChangeset
for help on using the changeset viewer.