Skip to content

Commit 96af501

Browse files
westonruterclaude
andcommitted
Docs: Narrow the get_post_time() return type by date format.
For each format character whose output has a fixed range, such as `w` for `'0'` through `'6'` or `m` for `'01'` through `'12'`, the conditional return type now gives that range, mirroring what PHPStan infers for `DateTimeInterface::format()`. Formats with an open-ended numeric output give `numeric-string`. Formats that `wp_date()` translates (`D`, `l`, `M`, `F`, `a`, and `A`) and the PHP 8.2+ `X` and `x` remain `string`. With `w` narrowed, the weekday number passed to `WP_Locale::get_weekday()` in the_weekday() and the_weekday_date() already satisfies `int<0, 6>` after an int cast, so the `clamp()` calls are no longer needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0181606 commit 96af501

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

‎src/wp-includes/general-template.php‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,21 @@ function get_the_time( $format = '', $post = null ) {
31813181
* @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
31823182
* False on failure.
31833183
*
3184-
* @phpstan-return ( $format is 'U'|'G' ? int|false : string|false )
3184+
* @phpstan-return (
3185+
* $format is 'U'|'G' ? int|false : (
3186+
* $format is 'w' ? '0'|'1'|'2'|'3'|'4'|'5'|'6'|false : (
3187+
* $format is 'N' ? '1'|'2'|'3'|'4'|'5'|'6'|'7'|false : (
3188+
* $format is 'L'|'I' ? '0'|'1'|false : (
3189+
* $format is 't' ? '28'|'29'|'30'|'31'|false : (
3190+
* $format is 'm'|'h' ? '01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09'|'10'|'11'|'12'|false : (
3191+
* $format is 'n'|'g' ? '1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'10'|'11'|'12'|false : (
3192+
* $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 : (
3193+
* $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 : (
3194+
* $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 : (
3195+
* $format is 'z'|'W'|'o'|'Y'|'y'|'B'|'i'|'s'|'u'|'v'|'Z' ? numeric-string|false :
3196+
* string|false
3197+
* ) ) ) ) ) ) ) ) ) )
3198+
* )
31853199
*/
31863200
function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
31873201
$post = get_post( $post );
@@ -3442,7 +3456,7 @@ function the_weekday() {
34423456
return;
34433457
}
34443458

3445-
$the_weekday = $wp_locale->get_weekday( clamp( (int) $weekday_number, 0, 6 ) );
3459+
$the_weekday = $wp_locale->get_weekday( (int) $weekday_number );
34463460

34473461
/**
34483462
* Filters the localized weekday of the post, for display.
@@ -3483,7 +3497,7 @@ function the_weekday_date( $before = '', $after = '' ) {
34833497

34843498
if ( false !== $weekday_number && $currentday !== $previousweekday ) {
34853499
$the_weekday_date .= $before;
3486-
$the_weekday_date .= $wp_locale->get_weekday( clamp( (int) $weekday_number, 0, 6 ) );
3500+
$the_weekday_date .= $wp_locale->get_weekday( (int) $weekday_number );
34873501
$the_weekday_date .= $after;
34883502
$previousweekday = $currentday;
34893503
}

0 commit comments

Comments
 (0)