Skip to content

Date/Time: Remove mysql2date() usage from core - #14467

Open
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:ticket/48936-remove-mysql2date-phase-1
Open

faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:ticket/48936-remove-mysql2date-phase-1

Conversation

@faisalahammad

Copy link
Copy Markdown

https://core.trac.wordpress.org/ticket/48936

What and why

mysql2date() always parses its input in the site timezone. When it is given a UTC value and a format that prints a timezone, the output shows the site offset instead of UTC. Core already has better tools for each case: get_post_time(), wp_date(), get_gmt_from_date(), and plain strtotime() for comparisons. This PR replaces the first batch of mysql2date() calls with those, and fixes get_comment_time() so $gmt = true reads the stored date as UTC.

Scope

In scope (first pass):

  • get_comment_date() and get_comment_time() parse dates directly, the same way get_post_time() does. With $gmt = true, a format with timezone characters now outputs +00:00 instead of the site offset.
  • The RSS2, RDF, RSS2 comments and Atom comments feeds, and the WXR export, pass their final format straight to get_post_time() / get_comment_time().
  • WP::send_headers() builds Last-Modified from the raw GMT values with gmdate().
  • XML-RPC _convert_date(), _convert_date_gmt() and the if_not_modified_since check in wp_getPosts.
  • Customizer changeset scheduling, the autosave checks on the post edit screens, and the signup expiry checks in ms-functions.php use strtotime().

Output from all touched callers is unchanged, except for the get_comment_time() GMT fix above.

Out of scope, for follow-up patches:

  • Admin display calls that format local time.
  • List table and upgrade.php calls. They treat UTC as local today, and fixing that changes output.
  • deprecated.php and the bundled themes.
  • Deprecating mysql2date() itself.

Notes for reviewers:

  • Feeds and export now pass the final format to the get_post_time / get_comment_time filters instead of 'Y-m-d H:i:s'. feed-rdf.php now runs the get_post_time filter.
  • UTC values that fall inside a site timezone DST gap are no longer shifted by an hour.

Testing

New tests, all tagged @ticket 48936:

  • tests/phpunit/tests/date/getCommentDate.php
  • tests/phpunit/tests/date/xmlrpc.php
  • tests/phpunit/tests/wp/sendHeaders.php
npm run env:start
npm run env:install
npm run test:php -- --group 48936
npm run test:php -- --group date,datetime,comment,feed,xmlrpc,customize,wp,export
npm run test:php -- -c tests/phpunit/multisite.xml --filter signup

On trunk, only the GMT time zone test fails. The other new tests pass before and after, which confirms the output did not change.

Manual check:

  1. Set Settings > General > Timezone to a non-UTC city, for example Helsinki.
  2. Load /feed/, /feed/rdf/ and /comments/feed/. The pubDate / dc:date / updated values should match the GMT columns in the database, and the Last-Modified response header should be in GMT.
  3. Run Tools > Export and check the pubDate values in the file.
  4. get_comment_time( 'c', true ) should end in +00:00.

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props faisalahammad.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@faisalahammad
faisalahammad force-pushed the ticket/48936-remove-mysql2date-phase-1 branch from 2f42755 to 9ec0bd0 Compare October 18, 2026 18:02
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Replace `mysql2date()` in the comment template tags, feeds, export,
`WP::send_headers()`, XML-RPC, Customizer scheduling, autosave checks
and signup expiry with `get_post_time()`, `wp_date()`,
`get_gmt_from_date()` and `strtotime()`.

This also fixes `get_comment_time()` with `$gmt` set to true. It parsed
the date in the site timezone, so formats with timezone characters
showed the site offset instead of UTC.

See #48936.
@faisalahammad
faisalahammad force-pushed the ticket/48936-remove-mysql2date-phase-1 branch from 9ec0bd0 to 13f05b5 Compare October 18, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant