WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/06/2015 03:18:45 AM (5 years ago)
Author:
wonderboymusic
Message:

REST API: add a utility function, mysql_to_rfc3339() to functions.php

Background:
https://github.com/WP-API/WP-API/commit/6d0ad766ca525c7a3aee921b66554ddf21a5c023

Props rmmcue.
See #33982.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r34828 r34846  
    681681 *
    682682 * Using an associative array:
    683  * 
     683 *
    684684 *     add_query_arg( array(
    685685 *         'key1' => 'value1',
    686686 *         'key2' => 'value2',
    687687 *     ), 'http://example.com' );
    688  * 
     688 *
    689689 * Omitting the URL from either use results in the current URL being used
    690690 * (the value of `$_SERVER['REQUEST_URI']`).
    691  * 
     691 *
    692692 * Values are expected to be encoded appropriately with urlencode() or rawurlencode().
    693693 *
     
    50235023    <?php
    50245024}
     5025
     5026/**
     5027 * Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
     5028 *
     5029 * Explicitly strips timezones, as datetimes are not saved with any timezone
     5030 * information. Including any information on the offset could be misleading.
     5031 *
     5032 * @since 4.4.0
     5033 *
     5034 * @param string $date_string Date string to parse and format.
     5035 * @return string Date formatted for ISO8601/RFC3339.
     5036 */
     5037function mysql_to_rfc3339( $date_string ) {
     5038    $formatted = mysql2date( 'c', $date_string, false );
     5039
     5040    // Strip timezone information
     5041    return preg_replace( '/(?:Z|[+-]\d{2}(?::\d{2})?)$/', '', $formatted );
     5042}
Note: See TracChangeset for help on using the changeset viewer.