Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #151 from briannaorg/fix-131-81
Browse files Browse the repository at this point in the history
Display comment times with default functions
  • Loading branch information
allancole authored Oct 19, 2018
2 parents 8c168f3 + e5f6dbd commit 3b361b7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 60 deletions.
2 changes: 1 addition & 1 deletion classes/class-twentynineteen-walker-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function html5_comment( $comment, $depth, $args ) {
<a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
<?php /* translators: 1: comment date, 2: comment time */ ?>
<time datetime="<?php comment_time( 'c' ); ?>" title="<?php printf( __( '%1$s at %2$s', 'twentynineteen' ), get_comment_date( '', $comment ), get_comment_time() ); ?>">
<?php echo twentynineteen_human_time_diff( get_comment_date( 'U' ) ); ?>
<?php printf( __( '%1$s at %2$s', 'twentynineteen' ), get_comment_date( '', $comment ), get_comment_time() ); ?>
</time>
</a>
<?php
Expand Down
59 changes: 0 additions & 59 deletions inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,65 +169,6 @@ function twentynineteen_header_featured_image_css() {
}
endif;

if ( ! function_exists( 'twentynineteen_human_time_diff' ) ) :
/**
* Same as core's human_time_diff(), only in the "ago" context,
* which is different for some languages.
*
* @param int $from Unix timestamp from which the difference begins.
* @param int $to Optional Unix timestamp to end the time difference. Defaults to time() if not set.
* @return string Human readable time difference.
*/
function twentynineteen_human_time_diff( $from, $to = '' ) {
if ( empty( $to ) ) {
$to = time();
}

$diff = (int) abs( $to - $from );

if ( $diff < HOUR_IN_SECONDS ) {
$mins = round( $diff / MINUTE_IN_SECONDS );
if ( $mins <= 1 ) {
$mins = 1;
}
/* translators: min=minute */
$since = sprintf( _n( '%s min ago', '%s mins ago', $mins, 'twentynineteen' ), $mins );
} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
$hours = round( $diff / HOUR_IN_SECONDS );
if ( $hours <= 1 ) {
$hours = 1;
}
$since = sprintf( _n( '%s hour ago', '%s hours ago', $hours, 'twentynineteen' ), $hours );
} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
$days = round( $diff / DAY_IN_SECONDS );
if ( $days <= 1 ) {
$days = 1;
}
$since = sprintf( _n( '%s day ago', '%s days ago', $days, 'twentynineteen' ), $days );
} elseif ( $diff < 30 * DAY_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
$weeks = round( $diff / WEEK_IN_SECONDS );
if ( $weeks <= 1 ) {
$weeks = 1;
}
$since = sprintf( _n( '%s week ago', '%s weeks ago', $weeks, 'twentynineteen' ), $weeks );
} elseif ( $diff < YEAR_IN_SECONDS && $diff >= 30 * DAY_IN_SECONDS ) {
$months = round( $diff / ( 30 * DAY_IN_SECONDS ) );
if ( $months <= 1 ) {
$months = 1;
}
$since = sprintf( _n( '%s month ago', '%s months ago', $months, 'twentynineteen' ), $months );
} elseif ( $diff >= YEAR_IN_SECONDS ) {
$years = round( $diff / YEAR_IN_SECONDS );
if ( $years <= 1 ) {
$years = 1;
}
$since = sprintf( _n( '%s year ago', '%s years ago', $years, 'twentynineteen' ), $years );
}

return $since;
}
endif;

if ( ! function_exists( 'twentynineteen_comment_avatar' ) ) :
/**
* Returns the HTML markup to generate a user avatar.
Expand Down

0 comments on commit 3b361b7

Please sign in to comment.