Activity::when( object $object )

Description #

Return the human readable date of an activity which can be compared to other activity.

Parameters #

  • $object
    object (Required) Activity object.

Changelog #

VersionDescription
4.1.2Introduced.

Source #

File: includes/class/class-activity.php

	public function when( $object ) {
		$date = strtotime( $object->date );

		if ( $date >= strtotime( '-30 minutes' ) ) {
			$when = __( 'Just now', 'anspress-question-answer' );
		} elseif ( $date >= strtotime( '-24 hours' ) ) {
			$when = __( 'Today', 'anspress-question-answer' );
		} elseif ( $date >= strtotime( '-48 hours' ) ) {
			$when = __( 'Yesterday', 'anspress-question-answer' );
		} elseif ( $date <= strtotime( '1 year' ) ) {
			$when = date_i18n( 'M', $date );
		} else {
			$when = date_i18n( 'M Y', $date );
		}

		return $when;
	}

Leave a Reply

Your email address will not be published.

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

Add your comment