mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
Update 1.3.29
This commit is contained in:
@@ -13,6 +13,68 @@ class UM_DateTime {
|
||||
return current_time( $format );
|
||||
}
|
||||
|
||||
/***
|
||||
*** @Show a cool time difference between 2 timestamps
|
||||
***/
|
||||
function time_diff( $from, $to = '' ) {
|
||||
if ( empty( $to ) ) {
|
||||
$to = time();
|
||||
}
|
||||
$diff = (int) abs( $to - $from );
|
||||
if ( $diff < 60 ) {
|
||||
|
||||
$since = __('just now','ultimatemember');
|
||||
|
||||
} elseif ( $diff < HOUR_IN_SECONDS ) {
|
||||
|
||||
$mins = round( $diff / MINUTE_IN_SECONDS );
|
||||
if ( $mins <= 1 )
|
||||
$mins = 1;
|
||||
if ( $mins == 1 ) {
|
||||
$since = sprintf( __('%s min','ultimatemember'), $mins );
|
||||
} else {
|
||||
$since = sprintf( __('%s mins','ultimatemember'), $mins );
|
||||
}
|
||||
|
||||
} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
|
||||
|
||||
$hours = round( $diff / HOUR_IN_SECONDS );
|
||||
if ( $hours <= 1 )
|
||||
$hours = 1;
|
||||
if ( $hours == 1 ) {
|
||||
$since = sprintf( __('%s hr','ultimatemember'), $hours );
|
||||
} else {
|
||||
$since = sprintf( __('%s hrs','ultimatemember'), $hours );
|
||||
}
|
||||
|
||||
} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
|
||||
|
||||
$days = round( $diff / DAY_IN_SECONDS );
|
||||
if ( $days <= 1 )
|
||||
$days = 1;
|
||||
if ( $days == 1 ) {
|
||||
$since = sprintf( __('Yesterday at %s','ultimatemember'), date('g:ia', $from ) );
|
||||
} else {
|
||||
$since = sprintf(__('%s at %s','ultimatemember'), date('F d', $from ), date('g:ia', $from ) );
|
||||
}
|
||||
|
||||
} elseif ( $diff < 30 * DAY_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
|
||||
|
||||
$since = sprintf(__('%s at %s','ultimatemember'), date('F d', $from ), date('g:ia', $from ) );
|
||||
|
||||
} elseif ( $diff < YEAR_IN_SECONDS && $diff >= 30 * DAY_IN_SECONDS ) {
|
||||
|
||||
$since = sprintf(__('%s at %s','ultimatemember'), date('F d', $from ), date('g:ia', $from ) );
|
||||
|
||||
} elseif ( $diff >= YEAR_IN_SECONDS ) {
|
||||
|
||||
$since = sprintf(__('%s at %s','ultimatemember'), date( 'F d, Y', $from ), date('g:ia', $from ) );
|
||||
|
||||
}
|
||||
|
||||
return apply_filters( 'um_human_time_diff', $since, $diff, $from, $to );
|
||||
}
|
||||
|
||||
/***
|
||||
*** @Get age
|
||||
***/
|
||||
|
||||
Reference in New Issue
Block a user