REST API: add a utility function, mysql_to_rfc3339()
to functions.php
Background:
6d0ad766ca
Props rmmcue.
See #33982.
git-svn-id: https://develop.svn.wordpress.org/trunk@34846 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d2bb4d6745
commit
5d0718497c
@ -680,15 +680,15 @@ function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urle
|
|||||||
* add_query_arg( 'key', 'value', 'http://example.com' );
|
* add_query_arg( 'key', 'value', 'http://example.com' );
|
||||||
*
|
*
|
||||||
* Using an associative array:
|
* Using an associative array:
|
||||||
*
|
*
|
||||||
* add_query_arg( array(
|
* add_query_arg( array(
|
||||||
* 'key1' => 'value1',
|
* 'key1' => 'value1',
|
||||||
* 'key2' => 'value2',
|
* 'key2' => 'value2',
|
||||||
* ), 'http://example.com' );
|
* ), 'http://example.com' );
|
||||||
*
|
*
|
||||||
* Omitting the URL from either use results in the current URL being used
|
* Omitting the URL from either use results in the current URL being used
|
||||||
* (the value of `$_SERVER['REQUEST_URI']`).
|
* (the value of `$_SERVER['REQUEST_URI']`).
|
||||||
*
|
*
|
||||||
* Values are expected to be encoded appropriately with urlencode() or rawurlencode().
|
* Values are expected to be encoded appropriately with urlencode() or rawurlencode().
|
||||||
*
|
*
|
||||||
* Setting any query variable's value to boolean false removes the key (see remove_query_arg()).
|
* Setting any query variable's value to boolean false removes the key (see remove_query_arg()).
|
||||||
@ -5022,3 +5022,21 @@ function wp_post_preview_js() {
|
|||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
|
||||||
|
*
|
||||||
|
* Explicitly strips timezones, as datetimes are not saved with any timezone
|
||||||
|
* information. Including any information on the offset could be misleading.
|
||||||
|
*
|
||||||
|
* @since 4.4.0
|
||||||
|
*
|
||||||
|
* @param string $date_string Date string to parse and format.
|
||||||
|
* @return string Date formatted for ISO8601/RFC3339.
|
||||||
|
*/
|
||||||
|
function mysql_to_rfc3339( $date_string ) {
|
||||||
|
$formatted = mysql2date( 'c', $date_string, false );
|
||||||
|
|
||||||
|
// Strip timezone information
|
||||||
|
return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user