Date/Time: Restore the previous behavior of date_i18n() where invalid input would result in current time.

Make `wp_date()` return `false` on invalid timestamp input, for consistency with upstream PHP `date()` function.

Props Rarst.
Fixes #28636.
Built from https://develop.svn.wordpress.org/trunk@45914


git-svn-id: http://core.svn.wordpress.org/trunk@45725 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-08-29 23:18:55 +00:00
parent 3965d4735c
commit 16c43f368d
2 changed files with 10 additions and 4 deletions

View File

@ -163,8 +163,12 @@ function wp_timezone() {
* @return string The date, translated if locale specifies it.
*/
function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) {
$timestamp = $timestamp_with_offset;
// If timestamp is omitted it should be current time (summed with offset, unless `$gmt` is true).
$timestamp = $timestamp_with_offset ? $timestamp_with_offset : current_time( 'timestamp', $gmt );
if ( ! is_numeric( $timestamp ) ) {
$timestamp = current_time( 'timestamp', $gmt );
}
/*
* This is a legacy implementation quirk that the returned timestamp is also with offset.
@ -218,13 +222,15 @@ function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) {
* @param int $timestamp Optional. Unix timestamp. Defaults to current time.
* @param DateTimeZone $timezone Optional. Timezone to output result in. Defaults to timezone
* from site settings.
* @return string The date, translated if locale specifies it.
* @return string|false The date, translated if locale specifies it. False on invalid timestamp input.
*/
function wp_date( $format, $timestamp = null, $timezone = null ) {
global $wp_locale;
if ( ! $timestamp ) {
if ( null === $timestamp ) {
$timestamp = time();
} elseif ( ! is_numeric( $timestamp ) ) {
return false;
}
if ( ! $timezone ) {

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-45913';
$wp_version = '5.3-alpha-45914';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.