docs: def adjust_version_as_of(version, relations_as_of):
          """
          Adjusts the passed version's as_of time to an appropriate value, and
          returns it.
  
          ``relations_as_of`` is used to fix the point in time for the version;
          this affects which related objects are returned when querying for
          object relations.
          Valid ``relations_as_of`` values and how this affects the returned
          version's as_of attribute:
          - 'start': version start date
          - 'end': version end date - 1 microsecond (no effect if version is
              current version)
          - datetime object: given datetime (raises ValueError if given datetime
              not valid for version)
          - None: unset (related object queries will not be restricted to a
              point in time)
  
          :param Versionable object: object whose as_of will be adjusted as
              requested.
          :param mixed relations_as_of: valid values are the strings 'start' or
              'end', or a datetime object.
          :return: Versionable
          """
          if not version:
              return version
  
          if relations_as_of == 'end':
              if version.is_current:
                  # Ensure that version._querytime is active, in case it wasn't
                  # before.
                  version.as_of = None
              else:
                  version.as_of = version.version_end_date - datetime.timedelta(
                      microseconds=1)
          elif relations_as_of == 'start':
              version.as_of = version.version_start_date
          elif isinstance(relations_as_of, datetime.datetime):
              as_of = relations_as_of.astimezone(utc)
              if not as_of >= version.version_start_date:
                  raise ValueError(
                      "Provided as_of '{}' is earlier than version's start "
                      "time '{}'".format(
                          as_of.isoformat(),
                          version.version_start_date.isoformat()
                      )
                  )
              if version.version_end_date is not None \
                      and as_of >= version.version_end_date:
                  raise ValueError(
                      "Provided as_of '{}' is later than version's start "
                      "time '{}'".format(
                          as_of.isoformat(),
                          version.version_end_date.isoformat()
                      )
                  )
              version.as_of = as_of
          elif relations_as_of is None:
              version._querytime = QueryTime(time=None, active=False)
          else:
              raise TypeError(
                  "as_of parameter must be 'start', 'end', None, or datetime "
                  "object")
  
          return version