/**
  * Returns a filtered version of this time.
  *
  * @param string $filter The filter context.
  * @return self|array|bool|object|BTB_Booking
  */
 public function filter($filter)
 {
     if ($this->filter == $filter) {
         return $this;
     }
     if ($filter == 'raw') {
         return self::get_instance($this->ID);
     }
     return btb_sanitize_time($this, $filter);
 }
/**
 * @brief Retrieves time data given a time ID or time object.
 *
 * @see sanitize_time() for optional $filter values. Also, the parameter $time
 * must be given as a variable, since it is passed by reference.
 *
 * @param int|BTB_Time		$time Time ID or BTB_Time object.
 * @param string 			$output Optional, default is Object. Accepts OBJECT, ARRAY_A or ARRAY_N.
 * @param string			$filter Optional. Type of filter to apply. Accepts 'raw', 'edit', 'db', 'display',
 *									'attribute' or 'js'. Default 'raw'.
 * @return BTB_Time|array|null	Type corresponding to $output on success or null on failure.
 *						      	When $output is OBJECT, a `BTB_Time` instance is returned.
 */
function btb_get_time($time, $output = OBJECT, $filter = 'raw')
{
    if ($time instanceof BTB_Time) {
        $_time = $time;
    } elseif (is_object($time)) {
        if (empty($time->filter)) {
            $_time = btb_sanitize_time($time, 'raw');
            $_time = new BTB_Time($_time);
        } elseif ('raw' == $time->filter) {
            $_time = new BTB_Time($time);
        } else {
            $_time = BTB_Time::get_instance($time->ID);
        }
    } else {
        $_time = BTB_Time::get_instance($time);
    }
    if (!$_time) {
        return null;
    }
    $_time = $_time->filter($filter);
    if ($output == ARRAY_A) {
        return $_time->to_array();
    } elseif ($output == ARRAY_N) {
        return array_values($_time->to_array());
    }
    return $_time;
}