Skip to content

Commit

Permalink
Refactor post date relative time rendering logic to handle future dat…
Browse files Browse the repository at this point in the history
…es (#62979)

Co-authored-by: amitraj2203 <[email protected]>
Co-authored-by: noisysocks <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: mrfoxtalbot <[email protected]>
  • Loading branch information
5 people authored Jul 2, 2024
1 parent 42adfaf commit 44a82f1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/block-library/src/post-date/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ function render_block_core_post_date( $attributes, $content, $block ) {
$post_ID = $block->context['postId'];

if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
// translators: %s: human-readable time difference.
$formatted_date = sprintf( __( '%s ago', 'gutenberg' ), human_time_diff( get_post_timestamp( $post_ID ) ) );
$post_timestamp = get_post_timestamp( $post_ID );
if ( $post_timestamp > time() ) {
// translators: %s: human-readable time difference.
$formatted_date = sprintf( __( '%s from now', 'gutenberg' ), human_time_diff( $post_timestamp ) );
} else {
// translators: %s: human-readable time difference.
$formatted_date = sprintf( __( '%s ago', 'gutenberg' ), human_time_diff( $post_timestamp ) );
}
} else {
$formatted_date = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
}
Expand Down

0 comments on commit 44a82f1

Please sign in to comment.