def matches_querytime(instance, querytime):
    """
    Checks whether the given instance satisfies the given QueryTime object.

    :param instance: an instance of Versionable
    :param querytime: QueryTime value to check against
    """
    if not querytime.active:
        return True

    if not querytime.time:
        return instance.version_end_date is None

    return (instance.version_start_date <= querytime.time and (
        instance.version_end_date is None or
        instance.version_end_date > querytime.time))