Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ac5176b
Docs: Clarify the weekday range in WP_Locale::get_weekday().
rootzero00 Oct 24, 2026
164f132
Docs: Update weekday range PHPStan baselines.
rootzero00 Oct 24, 2026
fefbbea
Docs: Address WP_Locale parameter annotation review.
rootzero00 Oct 25, 2026
e4f3252
Date/Time: Clamp the start of the week in get_calendar().
westonruter Oct 25, 2026
0181606
Date/Time: Handle a missing post weekday in the_weekday() and the_wee…
westonruter Oct 25, 2026
96af501
Docs: Narrow the get_post_time() return type by date format.
westonruter Oct 25, 2026
fbd1a8e
Date/Time: Pass the weekday number to WP_Locale::get_weekday() as an …
westonruter Oct 25, 2026
bed0a3a
Date/Time: Return false from wp_date() when the timestamp cannot be p…
westonruter Oct 25, 2026
e26b0b9
Docs: Keep the full month number type for WP_Locale::get_month().
westonruter Oct 25, 2026
63618bf
Merge branch 'trunk' into docs/64522-weekday-range
westonruter Oct 27, 2026
38241bc
Merge branch 'trunk' into docs/64522-weekday-range
westonruter Nov 13, 2026
3dd8ee6
Normalize start_of_week modulo 7 instead of clamping it
westonruter Nov 13, 2026
67fd6be
Simplify start_of_week normalization with absint()
westonruter Nov 13, 2026
68edf1f
Apply the_weekday filter even when the post date is invalid
westonruter Nov 13, 2026
bb91b19
Only get the post time in the_weekday_date() when the day changes
westonruter Nov 13, 2026
0ffccad
Document the expected value contract for the get_post_time filter
westonruter Nov 13, 2026
185ccf1
Add ticket annotation to the unparsable numeric timestamp test
westonruter Nov 13, 2026
faf4666
Document the invalid post date behavior change in weekday template tags
westonruter Nov 13, 2026
780802a
Use get_echo() to capture output in new weekday tests
westonruter Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/wp-includes/class-wp-locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ public function init() {
*
* @param int $weekday_number 0 for Sunday through 6 Saturday.
* @return string Full translated weekday.
*
* @phpstan-param int<0, 6> $weekday_number
*/
public function get_weekday( $weekday_number ) {
return $this->weekday[ $weekday_number ];
Expand Down Expand Up @@ -355,6 +357,8 @@ public function get_month_abbrev( $month_name ) {
*
* @param string|int $month_number '01' through '12'.
* @return string Translated genitive month name.
*
* @phpstan-param int<1, 12>|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'10'|'11'|'12'|'01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09' $month_number
*/
public function get_month_genitive( $month_number ) {
return $this->month_genitive[ zeroise( $month_number, 2 ) ];
Expand All @@ -369,6 +373,8 @@ public function get_month_genitive( $month_number ) {
*
* @param string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version.
* @return string Translated version
*
* @phpstan-param 'am'|'pm'|'AM'|'PM' $meridiem
*/
public function get_meridiem( $meridiem ) {
return $this->meridiem[ $meridiem ];
Expand Down
7 changes: 6 additions & 1 deletion src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ function wp_date( $format, $timestamp = null, $timezone = null ) {
}

$datetime = date_create( '@' . $timestamp );

if ( false === $datetime ) {
return false;
}

$datetime->setTimezone( $timezone );

if ( empty( $wp_locale->month ) || empty( $wp_locale->weekday ) ) {
Expand All @@ -269,7 +274,7 @@ function wp_date( $format, $timestamp = null, $timezone = null ) {
$new_format = '';
$format_length = strlen( $format );
$month = $wp_locale->get_month( $datetime->format( 'm' ) );
$weekday = $wp_locale->get_weekday( $datetime->format( 'w' ) );
$weekday = $wp_locale->get_weekday( (int) $datetime->format( 'w' ) );

for ( $i = 0; $i < $format_length; $i++ ) {
switch ( $format[ $i ] ) {
Expand Down
46 changes: 39 additions & 7 deletions src/wp-includes/general-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2666,7 +2666,7 @@ function get_calendar( $args = array() ) {
}

// week_begins = 0 stands for Sunday.
$week_begins = (int) get_option( 'start_of_week' );
$week_begins = absint( get_option( 'start_of_week' ) ) % 7;

// Read the current date.
list( $current_year, $current_month, $current_day ) = array_map( 'intval', explode( '-', current_time( 'Y-m-j' ) ) );
Expand Down Expand Up @@ -3181,7 +3181,21 @@ function get_the_time( $format = '', $post = null ) {
* @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
* False on failure.
*
* @phpstan-return ( $format is 'U'|'G' ? int|false : string|false )
* @phpstan-return (
* $format is 'U'|'G' ? int|false : (
* $format is 'w' ? '0'|'1'|'2'|'3'|'4'|'5'|'6'|false : (
* $format is 'N' ? '1'|'2'|'3'|'4'|'5'|'6'|'7'|false : (
* $format is 'L'|'I' ? '0'|'1'|false : (
* $format is 't' ? '28'|'29'|'30'|'31'|false : (
* $format is 'm'|'h' ? '01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09'|'10'|'11'|'12'|false : (
* $format is 'n'|'g' ? '1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'10'|'11'|'12'|false : (
* $format is 'H' ? '00'|'01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09'|'10'|'11'|'12'|'13'|'14'|'15'|'16'|'17'|'18'|'19'|'20'|'21'|'22'|'23'|false : (
* $format is 'd' ? '01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09'|'10'|'11'|'12'|'13'|'14'|'15'|'16'|'17'|'18'|'19'|'20'|'21'|'22'|'23'|'24'|'25'|'26'|'27'|'28'|'29'|'30'|'31'|false : (
* $format is 'j' ? '1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'10'|'11'|'12'|'13'|'14'|'15'|'16'|'17'|'18'|'19'|'20'|'21'|'22'|'23'|'24'|'25'|'26'|'27'|'28'|'29'|'30'|'31'|false : (
* $format is 'z'|'W'|'o'|'Y'|'y'|'B'|'i'|'s'|'u'|'v'|'Z' ? numeric-string|false :
* string|false
* ) ) ) ) ) ) ) ) ) )
* )
*/
function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
$post = get_post( $post );
Expand Down Expand Up @@ -3217,8 +3231,14 @@ function get_post_time( $format = 'U', $gmt = false, $post = null, $translate =
/**
* Filters the localized time of the post.
*
* The filtered value should match the type and values that `$format` produces,
* for example, an integer for 'U' or 'G', or a numeric string from '0' to '6' for 'w'.
*
* @since 2.6.0
*
* @see get_post_time()
* @link https://www.php.net/manual/en/datetime.format.php
*
* @param string|int $time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
* @param string $format Format to use for retrieving the date of the post.
* Accepts 'G', 'U', or PHP date format.
Expand Down Expand Up @@ -3424,6 +3444,7 @@ function get_post_modified_time( $format = 'U', $gmt = false, $post = null, $tra
* Displays the localized weekday for the post.
*
* @since 0.71
* @since 7.2.0 Passes an empty string to the filter instead of 'Sunday' if the post date is invalid.
*
* @global WP_Locale $wp_locale WordPress date and time locale object.
*/
Expand All @@ -3436,7 +3457,12 @@ function the_weekday() {
return;
}

$the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
$the_weekday = '';
$weekday_number = get_post_time( 'w', false, $post );

if ( false !== $weekday_number ) {
$the_weekday = $wp_locale->get_weekday( (int) $weekday_number );
}

/**
* Filters the localized weekday of the post, for display.
Expand All @@ -3455,6 +3481,7 @@ function the_weekday() {
* the previous one output.
*
* @since 0.71
* @since 7.2.0 Outputs nothing instead of 'Sunday' if the post date is invalid.
*
* @global WP_Locale $wp_locale WordPress date and time locale object.
* @global string $currentday The day of the current post in the loop.
Expand All @@ -3475,10 +3502,15 @@ function the_weekday_date( $before = '', $after = '' ) {
$the_weekday_date = '';

if ( $currentday !== $previousweekday ) {
$the_weekday_date .= $before;
$the_weekday_date .= $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
$the_weekday_date .= $after;
$previousweekday = $currentday;
$weekday_number = get_post_time( 'w', false, $post );

if ( false !== $weekday_number ) {
$the_weekday_date .= $before;
$the_weekday_date .= $wp_locale->get_weekday( (int) $weekday_number );
$the_weekday_date .= $after;
}

$previousweekday = $currentday;
}

/**
Expand Down
10 changes: 0 additions & 10 deletions tests/phpstan/baselines/argument.type.neon
Original file line number Diff line number Diff line change
Expand Up @@ -838,11 +838,6 @@ parameters:
identifier: argument.type
count: 2
path: ../../../src/wp-includes/functions.php
-
message: '#^Parameter \#1 \$weekday_number of method WP_Locale\:\:get_weekday\(\) expects int, string given\.$#'
identifier: argument.type
count: 1
path: ../../../src/wp-includes/functions.php
-
message: '#^Parameter \#2 \$fallback_url of function wp_validate_redirect expects string, false given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -883,11 +878,6 @@ parameters:
identifier: argument.type
count: 2
path: ../../../src/wp-includes/general-template.php
-
message: '#^Parameter \#1 \$weekday_number of method WP_Locale\:\:get_weekday\(\) expects int, string\|false given\.$#'
identifier: argument.type
count: 2
path: ../../../src/wp-includes/general-template.php
-
message: '#^Parameter \#2 \$replace of function str_replace expects array\<string\>\|string, int\<1, max\> given\.$#'
identifier: argument.type
Expand Down
46 changes: 46 additions & 0 deletions tests/phpunit/tests/date/theDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,50 @@ static function ( $output ) {
the_weekday_date();
$this->assertSame( 'Filtered Wednesday', ob_get_clean() );
}

/**
* Tests that the_weekday_date() does not retrieve the post time when the day has not changed.
*
* @ticket 64522
*/
public function test_the_weekday_date_should_not_get_post_time_for_same_day() {
$GLOBALS['post'] = self::factory()->post->create_and_get(
array(
'post_date' => '2015-09-16 08:00:00',
)
);

$GLOBALS['currentday'] = '18.09.15';
$GLOBALS['previousweekday'] = '18.09.15';

$filter = new MockAction();
add_filter( 'get_post_time', array( $filter, 'filter' ) );

$weekday_date = get_echo( 'the_weekday_date' );
$this->assertSame( '', $weekday_date, 'No weekday should be output for the same day.' );
$this->assertSame( 0, $filter->get_call_count(), 'The post time should not be retrieved for the same day.' );
}

/**
* Tests that the_weekday_date() tracks the day change even when the post date is invalid.
*
* @ticket 64522
*/
public function test_the_weekday_date_should_track_day_change_for_invalid_post_date() {
$post = self::factory()->post->create_and_get(
array(
'post_date' => '2015-09-16 08:00:00',
)
);
$this->assertInstanceOf( WP_Post::class, $post );
$post->post_date = '';

$GLOBALS['post'] = $post;
$GLOBALS['currentday'] = '18.09.15';
$GLOBALS['previousweekday'] = '17.09.15';

$weekday_date = get_echo( 'the_weekday_date', array( 'before ', ' after' ) );
$this->assertSame( '', $weekday_date, 'Nothing should be output for an invalid post date.' );
$this->assertSame( '18.09.15', $GLOBALS['previousweekday'], 'The previous weekday should be updated to the current day.' );
}
}
28 changes: 28 additions & 0 deletions tests/phpunit/tests/date/wpDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ public function test_should_return_false_on_invalid_timestamp() {
$this->assertFalse( wp_date( DATE_RFC3339, 'invalid' ) );
}

/**
* Tests that a numeric timestamp which {@see date_create()} cannot parse returns false.
*
* @ticket 64522
*
* @dataProvider data_should_return_false_on_unparsable_numeric_timestamp
*
* @param int|float|string $timestamp Numeric timestamp.
*/
public function test_should_return_false_on_unparsable_numeric_timestamp( $timestamp ): void {
$this->assertTrue( is_numeric( $timestamp ), 'Expected the timestamp to pass the is_numeric() check.' );
$this->assertFalse( wp_date( DATE_RFC3339, $timestamp ) ); // @phpstan-ignore argument.type (Intentionally invalid input.)
}

/**
* Data provider for {@see self::test_should_return_false_on_unparsable_numeric_timestamp()}.
*
* @return array<non-falsy-string, array{ 0: int|float|string }>
*/
public static function data_should_return_false_on_unparsable_numeric_timestamp(): array {
return array(
'exponent notation' => array( '1e3' ),
'out-of-range float' => array( 1e20 ),
'leading whitespace' => array( ' 5' ),
'leading decimal' => array( '.5' ),
);
}

/**
* @ticket 48319
*/
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/tests/general/theWeekday.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,26 @@ static function ( $weekday ) {
$this->expectOutputString( 'Custom Friday' );
the_weekday();
}

/**
* Tests that the 'the_weekday' filter is applied with an empty string when the post date is invalid.
*
* @ticket 64522
*/
public function test_the_weekday_filter_should_apply_for_invalid_post_date() {
global $post;

$post = get_post( self::$post_id );
$this->assertInstanceOf( WP_Post::class, $post );
$post->post_date = '';

$filter = new MockAction();
add_filter( 'the_weekday', array( $filter, 'filter' ) );

$weekday = get_echo( 'the_weekday' );

$this->assertSame( '', $weekday, 'Nothing should be output for an invalid post date.' );
$this->assertSame( 1, $filter->get_call_count(), 'The the_weekday filter should be applied.' );
$this->assertSame( array( '' ), $filter->get_args()[0], 'The the_weekday filter should receive an empty string.' );
}
}
Loading