ap_human_time( string $time, boolean $unix = true, integer $show_full_date = 604800, boolean|string $format = false )

Description #

Return human readable time format.

Parameters #

  • $time
    string (Required) Time.
  • $unix
    boolean (Optional) Is $time is unix. Default value: true
  • $show_full_date
    integer (Optional) Show full date after some period. Default is 7 days in epoch. Default value: 604800
  • $format
    boolean | string (Optional) Date format. Default value: false

Changelog #

VersionDescription
2.4.7Introduced.

Source #

File: includes/functions.php

function ap_human_time( $time, $unix = true, $show_full_date = 604800, $format = false ) {
	if ( false === $format ) {
		$format = get_option( 'date_format' );
	}

	if ( ! is_numeric( $time ) && ! $unix ) {
		$time = strtotime( $time );
	}

	// If default date format is enabled then just return date.
	if ( ap_opt( 'default_date_format' ) ) {
		return date_i18n( $format, $time );
	}

	if ( $time ) {
		if ( $show_full_date + $time > current_time( 'timestamp', true ) ) {
			return sprintf(
				/* translators: %s: human-readable time difference */
				_x( '%s ago', 'anspress-question-answer' ),
				human_time_diff( $time, current_time( 'timestamp', true ) )
			);
		}

		return date_i18n( $format, $time );
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment