code: def convert_unit(value, unit, to):
      
      # Don't do anything if from and to units are equivalent
      if unit == to:
          return value
  
      units = ('W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns')
      factors = (7, 24, 60, 60, 1000, 1000, 1000)
  
      monthly_units = ('Y', 'Q', 'M')
      monthly_factors = (4, 3)
  
      try:
          i, j = units.index(unit), units.index(to)
      except ValueError:
          try:
              i, j = monthly_units.index(unit), monthly_units.index(to)
              factors = monthly_factors
          except ValueError:
              raise ValueError(
                  'Cannot convert to or from variable length interval'
              )
  
      factor = functools.reduce(operator.mul, factors[min(i, j) : max(i, j)], 1)
      assert factor > 1
  
      if i < j:
          return value * factor
  
      assert i > j
      return value // factor
docs: Convert `value`, is assumed to be in units of `unit`, to units of `to`.
  
      Parameters
      ----------
      value : Union[numbers.Real, ibis.expr.types.NumericValue]
  
      Returns
      -------
      Union[numbers.Integral, ibis.expr.types.NumericValue]
  
      Examples
      --------
      >>> one_second = 1000
      >>> x = convert_unit(one_second, 'ms', 's')
      >>> x
      1
      >>> one_second = 1
      >>> x = convert_unit(one_second, 's', 'ms')
      >>> x
      1000
      >>> x = convert_unit(one_second, 's', 's')
      >>> x
      1
      >>> x = convert_unit(one_second, 's', 'M')
      Traceback (most recent call last):
          ...
      ValueError: Cannot convert to or from variable length interval