Make WordPress Core

Changeset 51950


Ignore:
Timestamp:
10/29/2021 04:50:29 PM (3 years ago)
Author:
johnbillion
Message:

Date/Time: Improve the docblocks for various date and time related functions.

See #53399, #28992, #40653

File:
1 edited

Legend:

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

    r51911 r51950  
    1111 * Convert given MySQL date string into a different format.
    1212 *
    13  * `$format` should be a PHP date format string.
    14  * 'U' and 'G' formats will return a sum of timestamp with timezone offset.
    15  * `$date` is expected to be local time in MySQL format (`Y-m-d H:i:s`).
     13 *  - `$format` should be a PHP date format string.
     14 *  - 'U' and 'G' formats will return an integer sum of timestamp with timezone offset.
     15 *  - `$date` is expected to be local time in MySQL format (`Y-m-d H:i:s`).
    1616 *
    1717 * Historically UTC time could be passed to the function to produce Unix timestamp.
     
    2525 * @param string $date      Date string to convert.
    2626 * @param bool   $translate Whether the return date should be translated. Default true.
    27  * @return string|int|false Formatted date string or sum of Unix timestamp and timezone offset.
     27 * @return string|int|false Integer if `$format` is 'U' or 'G', string otherwise.
    2828 *                          False on failure.
    2929 */
     
    5454 * Retrieves the current time based on specified type.
    5555 *
    56  * The 'mysql' type will return the time in the format for MySQL DATETIME field.
    57  * The 'timestamp' type will return the current timestamp or a sum of timestamp
    58  * and timezone offset, depending on `$gmt`.
    59  * Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
    60  *
    61  * If $gmt is set to either '1' or 'true', then both types will use GMT time.
    62  * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
     56 *  - The 'mysql' type will return the time in the format for MySQL DATETIME field.
     57 *  - The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp
     58 *    and timezone offset, depending on `$gmt`.
     59 *  - Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
     60 *
     61 * If `$gmt` is a truthy value then both types will use GMT time, otherwise the
     62 * output is adjusted with the GMT offset for the site.
    6363 *
    6464 * @since 1.0.0
    65  *
    66  * @param string   $type Type of time to retrieve. Accepts 'mysql', 'timestamp',
     65 * @since 5.3.0 Now returns an integer if `$type` is 'U'. Previously a string was returned.
     66 *
     67 * @param string   $type Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U',
    6768 *                       or PHP date format string (e.g. 'Y-m-d').
    6869 * @param int|bool $gmt  Optional. Whether to use GMT timezone. Default false.
    69  * @return int|string Integer if $type is 'timestamp', string otherwise.
     70 * @return int|string Integer if `$type` is 'timestamp' or 'U', string otherwise.
    7071 */
    7172function current_time( $type, $gmt = 0 ) {
     
    8687
    8788/**
    88  * Retrieves the current time as an object with the timezone from settings.
     89 * Retrieves the current time as an object using the site's timezone.
    8990 *
    9091 * @since 5.3.0
     
    9798
    9899/**
    99  * Retrieves the timezone from site settings as a string.
    100  *
    101  * Uses the `timezone_string` option to get a proper timezone if available,
    102  * otherwise falls back to an offset.
     100 * Retrieves the timezone of the site as a string.
     101 *
     102 * Uses the `timezone_string` option to get a proper timezone name if available,
     103 * otherwise falls back to a manual UTC ± offset.
     104 *
     105 * Example return values:
     106 *
     107 *  - 'Europe/Rome'
     108 *  - 'America/North_Dakota/New_Salem'
     109 *  - 'UTC'
     110 *  - '-06:30'
     111 *  - '+00:00'
     112 *  - '+08:45'
    103113 *
    104114 * @since 5.3.0
    105115 *
    106  * @return string PHP timezone string or a ±HH:MM offset.
     116 * @return string PHP timezone name or a ±HH:MM offset.
    107117 */
    108118function wp_timezone_string() {
     
    126136
    127137/**
    128  * Retrieves the timezone from site settings as a `DateTimeZone` object.
     138 * Retrieves the timezone of the site as a `DateTimeZone` object.
    129139 *
    130140 * Timezone can be based on a PHP timezone string or a ±HH:MM offset.
Note: See TracChangeset for help on using the changeset viewer.