[wp-trac] [WordPress Trac] #48207: Implement new Comment Date Functions
WordPress Trac
noreply at wordpress.org
Thu Jan 22 12:33:44 UTC 2026
#48207: Implement new Comment Date Functions
--------------------------------------+-----------------------
Reporter: dshanske | Owner: pbearne
Type: enhancement | Status: assigned
Priority: normal | Milestone: 7.0
Component: Date/Time | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+-----------------------
Changes (by ozgursar):
* keywords: has-patch has-unit-tests needs-testing => has-patch has-unit-
tests
Comment:
== Test Report
=== Description
This report validates whether the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/7943
=== Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 144.0.0.0
- OS: macOS
- Theme: Twenty Twenty-One 2.7
- MU Plugins: None activated
- Plugins:
* Code Snippets 3.9.4
* Test Reports 1.2.1
=== Steps to Reproduce
1. Add the following snippet via Code Snippets plugin or directly into
your theme's functions.php to see the the output of the functions
`get_post_datetime()` and `get_post_timestamp()` provided with the patch.
{{{
/**
* Plugin Name: Test Comment DateTime Functions
* Description: Tests the new get_comment_datetime and
get_comment_timestamp functions
* Version: 1.0
*/
add_action('admin_notices', 'display_comment_datetime_tests');
function display_comment_datetime_tests() {
// Get a test comment
$comments = get_comments(array('number' => 1, 'status' => 'approve'));
if (empty($comments)) {
echo '<div class="notice notice-warning"><p>No comments found.
Please create a test comment first.</p></div>';
return;
}
$comment = $comments[0];
$comment_id = $comment->comment_ID;
echo '<div class="notice notice-info" style="padding: 20px;">';
echo '<h2>Comment DateTime Function Tests</h2>';
echo '<p><strong>Testing Comment ID:</strong> ' . $comment_id .
'</p>';
echo '<p><strong>Comment Text:</strong> ' .
esc_html(substr($comment->comment_content, 0, 100)) . '...</p>';
echo '<hr>';
// Test 1: Compare with existing functions
echo '<h3>1. Comparison with Existing Functions</h3>';
echo '<table class="widefat" style="width: auto; min-width: 600px;">';
echo '<tr><th>Method</th><th>Result</th></tr>';
echo '<tr><td><code>get_comment_date()</code></td><td>' .
get_comment_date('', $comment) . '</td></tr>';
echo '<tr><td><code>get_comment_time()</code></td><td>' .
get_comment_time('', $comment) . '</td></tr>';
// Test the new functions if they exist
if (function_exists('get_comment_datetime')) {
$datetime = get_comment_datetime($comment);
echo '<tr><td><code>get_comment_datetime()</code></td><td>';
if ($datetime) {
echo $datetime->format('Y-m-d H:i:s') . ' (DateTime object)';
} else {
echo 'false';
}
echo '</td></tr>';
} else {
echo '<tr><td><code>get_comment_datetime()</code></td><td
style="color: red;">Function not available</td></tr>';
}
if (function_exists('get_comment_timestamp')) {
$timestamp = get_comment_timestamp($comment);
echo '<tr><td><code>get_comment_timestamp()</code></td><td>' .
$timestamp . ' (' . date('Y-m-d H:i:s', $timestamp) . ')</td></tr>';
} else {
echo '<tr><td><code>get_comment_timestamp()</code></td><td
style="color: red;">Function not available</td></tr>';
}
echo '</table>';
// Test 2: Timezone handling
echo '<hr><h3>2. Timezone Handling</h3>';
if (function_exists('get_comment_datetime')) {
echo '<table class="widefat" style="width: auto; min-width:
600px;">';
echo '<tr><th>Timezone</th><th>DateTime Result</th></tr>';
$datetime_utc = get_comment_datetime($comment, 'gmt');
echo '<tr><td>UTC (GMT)</td><td>' . ($datetime_utc ?
$datetime_utc->format('Y-m-d H:i:s T') : 'false') . '</td></tr>';
$datetime_local = get_comment_datetime($comment, 'local');
echo '<tr><td>Local (Blog timezone)</td><td>' . ($datetime_local ?
$datetime_local->format('Y-m-d H:i:s T') : 'false') . '</td></tr>';
echo '</table>';
}
// Test 3: Edge cases
echo '<hr><h3>3. Edge Cases</h3>';
echo '<table class="widefat" style="width: auto; min-width: 600px;">';
echo '<tr><th>Test Case</th><th>Result</th></tr>';
if (function_exists('get_comment_datetime')) {
// Test with null comment
$null_result = get_comment_datetime(null);
echo '<tr><td>Null comment</td><td>' . ($null_result === false ?
'false (correct)' : 'unexpected result') . '</td></tr>';
// Test with invalid comment ID
$invalid_result = get_comment_datetime(999999);
echo '<tr><td>Invalid comment ID</td><td>' . ($invalid_result ===
false ? 'false (correct)' : 'unexpected result') . '</td></tr>';
}
if (function_exists('get_comment_timestamp')) {
// Test with null comment
$null_ts = get_comment_timestamp(null);
echo '<tr><td>Null comment (timestamp)</td><td>' . ($null_ts ===
false ? 'false (correct)' : 'unexpected result') . '</td></tr>';
}
echo '</table>';
// Test 4: Parallel with post functions
echo '<hr><h3>4. Parallel with Post DateTime Functions</h3>';
$post_id = $comment->comment_post_ID;
echo '<p><strong>Comparing comment and post datetime functions for
consistency</strong></p>';
echo '<table class="widefat" style="width: auto; min-width: 600px;">';
echo '<tr><th>Function Type</th><th>Comment Function</th><th>Post
Function</th></tr>';
if (function_exists('get_comment_datetime') &&
function_exists('get_post_datetime')) {
$comment_dt = get_comment_datetime($comment);
$post_dt = get_post_datetime($post_id);
echo '<tr><td>DateTime object</td><td>' . get_class($comment_dt) .
'</td><td>' . get_class($post_dt) . '</td></tr>';
}
if (function_exists('get_comment_timestamp') &&
function_exists('get_post_timestamp')) {
$comment_ts = get_comment_timestamp($comment);
$post_ts = get_post_timestamp($post_id);
echo '<tr><td>Timestamp type</td><td>' . gettype($comment_ts) .
'</td><td>' . gettype($post_ts) . '</td></tr>';
}
echo '</table>';
echo '</div>';
}
}}}
2. View WordPress dashboard to see the output as seen in the screenshots
=== Actual Results
1. ✅ Issue resolved with patch.
=== Supplemental Artifacts
Before:
[[Image(https://i.imgur.com/Xu5QCc9.png)]]
After:
[[Image(https://i.imgur.com/1sv9peC.jpeg)]]
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48207#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list