bp_core_time_since( int|string $older_date, int|bool $newer_date = false )
Get an English-language representation of the time elapsed since a given date.
Description Description
This function will return an English representation of the time elapsed since a given date. eg: 2 hours, 50 minutes eg: 4 days eg: 4 weeks, 6 days
Note that fractions of minutes are not represented in the return string. So an interval of 3 minutes will be represented by "3 minutes ago", as will an interval of 3 minutes 59 seconds.
Parameters Parameters
- $older_date
-
(int|string) (Required) The earlier time from which you're calculating the time elapsed. Enter either as an integer Unix timestamp, or as a date string of the format 'Y-m-d h:i:s'.
- $newer_date
-
(int|bool) (Optional) Unix timestamp of date to compare older date to. Default: false (current time).
Default value: false
Return Return
(string) String representing the time since the older date, eg "2 hours, 50 minutes".
Source Source
File: bp-core/bp-core-functions.php
function bp_core_time_since( $older_date, $newer_date = false ) { /** * Filters whether or not to bypass BuddyPress' time_since calculations. * * @since 1.7.0 * * @param bool $value Whether or not to bypass. * @param string $older_date Earlier time from which we're calculating time elapsed. * @param string $newer_date Unix timestamp of date to compare older time to. */ $pre_value = apply_filters( 'bp_core_time_since_pre', false, $older_date, $newer_date ); if ( false !== $pre_value ) { return $pre_value; } $newer_date = (int) $newer_date; $args = array( 'older_date' => $older_date, ); if ( $newer_date) { $args['newer_date'] = $newer_date; } // Calculate the time difference. $time_diff = bp_core_time_diff( $args ); /** * Filters the value to use if the time since is some time ago. * * @since 1.5.0 * * @param string $value String representing the time since the older date. */ $ago_text = apply_filters( 'bp_core_time_since_ago_text', /* translators: %s: the human time diff. */ __( '%s ago', 'buddypress' ) ); /** * Filters the value to use if the time since is right now. * * @since 1.5.0 * * @param string $value String representing the time since the older date. */ $output = apply_filters( 'bp_core_time_since_right_now_text', __( 'right now', 'buddypress' ) ); if ( is_array( $time_diff ) ) { $separator = _x( ',', 'Separator in time since', 'buddypress' ) . ' '; $diff_text = implode( $separator, $time_diff ); $output = sprintf( $ago_text, $diff_text ); } elseif ( false === $time_diff ) { /** * Filters the value to use if the time since is unknown. * * @since 1.5.0 * * @param string $value String representing the time since the older date. */ $unknown_text = apply_filters( 'bp_core_time_since_unknown_text', __( 'sometime', 'buddypress' ) ); $output = sprintf( $ago_text, $unknown_text ); } /** * Filters the English-language representation of the time elapsed since a given date. * * @since 1.7.0 * * @param string $output Final 'time since' string. * @param string $older_date Earlier time from which we're calculating time elapsed. * @param string $newer_date Unix timestamp of date to compare older time to. */ return apply_filters( 'bp_core_time_since', $output, $older_date, $newer_date ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
8.0.0 | Move the time difference calculation into bp_core_time_diff() . |
1.0.0 | Introduced. |