Skip to content

Commit 223c4ec

Browse files
committed
Privacy: A11y: Show time of privacy request status change.
Add the date and time of privacy request status changes in the privacy requests table. Previously, `human_time_diff()` was used in the first 24 hours, and only the date after 24 hours. Change the output to display both date and time after 24 hours, using the format used for comments. Props birgire, desrosj, afercia, xkon, tz-media, garrett-eclipse, sirlouen, sukhendu2002, sajjad67, fakhriaz, joedolson. Fixes #44267. git-svn-id: https://develop.svn.wordpress.org/trunk@60891 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 33b9bf1 commit 223c4ec

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

src/wp-admin/css/forms.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,11 @@ table.form-table td .updated p {
14531453
font-weight: 600;
14541454
}
14551455

1456+
.privacy_requests .status-date {
1457+
display: block;
1458+
font-weight: 400;
1459+
}
1460+
14561461
.wp-privacy-request-form {
14571462
clear: both;
14581463
}

src/wp-admin/includes/class-wp-privacy-requests-table.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public function column_status( $item ) {
461461
echo esc_html( $status_object->label );
462462

463463
if ( $timestamp ) {
464-
echo ' (' . $this->get_timestamp_as_date( $timestamp ) . ')';
464+
echo '<span class="status-date">' . $this->get_timestamp_as_date( $timestamp ) . '</span>';
465465
}
466466

467467
echo '</span>';
@@ -487,7 +487,14 @@ protected function get_timestamp_as_date( $timestamp ) {
487487
return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) );
488488
}
489489

490-
return date_i18n( get_option( 'date_format' ), $timestamp );
490+
return sprintf(
491+
/* translators: 1: privacy request date format, 2: privacy request time format. */
492+
__( '%1$s at %2$s' ),
493+
/* translators: privacy request date format. See https://www.php.net/manual/en/datetime.format.php */
494+
date_i18n( __( 'Y/m/d' ), $timestamp ),
495+
/* translators: privacy request time format. See https://www.php.net/manual/en/datetime.format.php */
496+
date_i18n( __( 'g:i a' ), $timestamp )
497+
);
491498
}
492499

493500
/**

tests/phpunit/tests/admin/wpPrivacyRequestsTable.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,41 @@ public function test_get_views_should_return_views_by_default() {
209209

210210
$this->assertSame( $expected, $this->get_mocked_class_instance()->get_views() );
211211
}
212+
213+
/**
214+
* Test the get_timestamp_as_date method formats timestamps correctly.
215+
*
216+
* @ticket 44267
217+
*
218+
* @covers WP_Privacy_Requests_Table::get_timestamp_as_date
219+
*/
220+
public function test_get_timestamp_as_date() {
221+
$table = $this->get_mocked_class_instance();
222+
223+
$reflection = new ReflectionClass( $table );
224+
$method = $reflection->getMethod( 'get_timestamp_as_date' );
225+
$method->setAccessible( true );
226+
227+
$date_format = __( 'Y/m/d' );
228+
$time_format = __( 'g:i a' );
229+
230+
$current_time = time();
231+
232+
$this->assertSame( '', $method->invoke( $table, '' ) );
233+
234+
// Test recent timestamp (less than 24 hours ago).
235+
$recent_time = $current_time - HOUR_IN_SECONDS;
236+
$result = $method->invoke( $table, $recent_time );
237+
$this->assertStringContainsString( 'ago', $result );
238+
239+
$old_time = $current_time - 2 * DAY_IN_SECONDS;
240+
$result = $method->invoke( $table, $old_time );
241+
242+
$date_part = date_i18n( $date_format, $old_time );
243+
$time_part = date_i18n( $time_format, $old_time );
244+
245+
$this->assertStringContainsString( $date_part, $result );
246+
$this->assertStringContainsString( 'at', $result );
247+
$this->assertStringContainsString( $time_part, $result );
248+
}
212249
}

0 commit comments

Comments
 (0)