LLMS_Date::convert_to_hours_minutes_string( $time )


Source Source

File: includes/class.llms.date.php

	public static function convert_to_hours_minutes_string( $time ) {
		$decimal_part = $time - floor( $time );
		settype( $time, 'integer' );
		if ( $time < 1 ) {
			return;
		}
		$hours   = floor( $time / 60 );
		$minutes = ( $time % 60 );
		$seconds = ( 60 * $decimal_part );

		$hours_string   = '';
		$minutes_string = '';
		$seconds_string = '';

		// Determine hours vs hour in string.
		if ( ! empty( $hours ) ) {
			if ( $hours > 1 ) {
				$hour_desc = __( 'hours', 'lifterlms' );
			} else {
				$hour_desc = __( 'hour', 'lifterlms' );
			}

			$hours_string = sprintf( __( '%1$d %2$s ', 'lifterlms' ), $hours, $hour_desc );
		} else {
			if ( ! empty( $seconds ) ) {
				if ( $seconds > 1 ) {
					$second_desc = __( 'seconds', 'lifterlms' );
				} else {
					$second_desc = __( 'second', 'lifterlms' );
				}

				$seconds_string = sprintf( ' %d %s', $seconds, $second_desc );

			}
		}

		// Determine minutes vs minute in string.
		if ( ! empty( $minutes ) ) {
			if ( $minutes > 1 ) {
				$minute_desc = __( 'minutes', 'lifterlms' );
			} else {
				$minute_desc = __( 'minute', 'lifterlms' );
			}

			$minutes_string = sprintf( ' %d %s', $minutes, $minute_desc );

		}

		return $hours_string . $minutes_string . $seconds_string;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.