protected function checkFilter($filter, $type, $test, $real)
    {
        if ($type == Table::TYPE_DATETIME) {
            if ($filter == Table::FILTER_BETWEEN
                    && is_array($test) && count($test) == 2) {
                $test = [
                    $test[0] ? new \DateTime('@' . $test[0]) : null,
                    $test[1] ? new \DateTime('@' . $test[1]) : null,
                ];
                if ($test[0] && $this->getDbTimezone())
                    $test[0]->setTimezone(new \DateTimeZone($this->getDbTimezone()));
                if ($test[1] && $this->getDbTimezone())
                    $test[1]->setTimezone(new \DateTimeZone($this->getDbTimezone()));
            } else if ($filter != Table::FILTER_BETWEEN
                    && is_scalar($test)) {
                $test = new \DateTime('@' . $test);
                if ($this->getDbTimezone())
                    $test->setTimezone(new \DateTimeZone($this->getDbTimezone()));
            } else {
                return null;
            }
        } else {
            if ($filter == Table::FILTER_BETWEEN) {
                if (!is_array($test) || count($test) != 2)
                    return null;
            } else if (!is_scalar($test)) {
                return null;
            }
        }

        switch ($filter) {
            case Table::FILTER_LIKE:
                return $real !== null && strpos($real, $test) !== false;
            case Table::FILTER_EQUAL:
                return $real !== null && $test == $real;
            case Table::FILTER_BETWEEN:
                if ($real === null)
                    return false;
                if ($test[0] !== null && $real < $test[0])
                    return false;
                if ($test[1] !== null && $real > $test[1])
                    return false;
                return true;
            case Table::FILTER_NULL:
                return $real === null;
            default:
                throw new \Exception("Unknown filter: $filter");
        }

        return false;
    }