[wp-trac] [WordPress Trac] #65046: get_weekstartend() has swapped variable names and comments for month and day
WordPress Trac
noreply at wordpress.org
Thu Apr 9 07:10:38 UTC 2026
#65046: get_weekstartend() has swapped variable names and comments for month and
day
---------------------------+-------------------------------------
Reporter: saratheonline | Owner: saratheonline
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Date/Time | Version: trunk
Severity: normal | Keywords: has-patch needs-testing
Focuses: |
---------------------------+-------------------------------------
In `get_weekstartend()` (src/wp-includes/functions.php), the variable
names
and comments for month and day are swapped, making the code misleading
and
a maintenance risk.
For a MySQL date string like "2024-12-15":
- Position 5-6 = "12" (month)
- Position 8-9 = "15" (day)
But the current code does the opposite:
// MySQL string month.
$mm = substr( $mysqlstring, 8, 2 ); // actually extracts the day
// MySQL string day.
$md = substr( $mysqlstring, 5, 2 ); // actually extracts the month
The result of mktime() is accidentally correct because the two errors
cancel
each other out, but anyone reading or maintaining this code would be
confused
— or worse, "fix" the variable names without updating mktime() and
introduce
a real bug.
== Proposed Fix ==
// MySQL string month.
$mm = substr( $mysqlstring, 5, 2 );
// MySQL string day.
$md = substr( $mysqlstring, 8, 2 );
// The timestamp for MySQL string day.
$day = mktime( 0, 0, 0, $mm, $md, $my );
This makes the variable names, comments, substr positions, and mktime()
argument order all consistent. The output is identical.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65046>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list