Sets time interval unit.

@param string $unit
@throws \InvalidArgumentException
@return $this
192985
public function setUnit($unit)
    {
        $validUnits = self::getValidUnits();

        if (!in_array($unit, $validUnits)) {
            throw new \InvalidArgumentException('Unknown value for time unit interval.');
        }

        $this->unit = $unit;

        return $this;
    }
902053
public function setObject($object)
    {
        if (! is_object($object)) {
            throw new InvalidArgumentException(
                sprintf('The parameter given to setObject method of %s class is not an object', get_called_class())
            );
        }

        $this->object = $object;
        return $this;
    }
64923
protected function setDuration($duration)
	{
		if (is_numeric($duration) && $duration >= 0)
		{
			$duration = new TimeInterval($duration);
		}
		
		if ( ! $duration instanceof TimeInterval)
		{
			throw new \InvalidArgumentException('The duration value must be a positive number value.');
		}
		
		$this->duration = $duration;
		
		return $this;
	}
617699
public function setTimeTransparency($transparency)
    {
        $transparency = strtoupper($transparency);
        if ($transparency === self::TIME_TRANSPARENCY_OPAQUE
            || $transparency === self::TIME_TRANSPARENCY_TRANSPARENT
        ) {
            $this->transparency = $transparency;
        } else {
            throw new \InvalidArgumentException('Invalid value for transparancy');
        }

        return $this;
    }
656745
public function addTime($time)
    {
        foreach ((array) $time as $value) {
            // only accept valid times (HH:mm)
            if ( ! preg_match('#([01][0-9]|2[0-3]):[0-5][0-9]#', $value)) {
                throw new InvalidArgumentException('Time must be valid: HH:mm.');
            }

            $this->times[] = $value;
        }

        return $this;
    }
1055603
public function setUnits($units)
    {
        $this->unitsByLocaleAndDomain = array();
        foreach ($units as $unit) {
            foreach ($unit->getTranslations() as $translation) {
                $this->unitsByLocaleAndDomain[$translation->getLocale()][$translation->getDomain()][] = $translation;
            }
        }
    }
512602
public function setTop($top) {
    if (!$this->isSupportedUnit($top)) {
      $this->triggerError("Value \"${top}\" does not use a supported unit.");
    }
    else {
      $this->top = $top;
    }
    return $this;
  }
216533
public function setValue($value)
    {
        if ($value instanceof DateInterval) {
            $value = Utils::now()->add($value);
        }

        if ($value instanceof DateTimeInterface) {
            $value = $value->getTimestamp();
        }

        return parent::setValue($value);
    }
927938
private static function resolveDateInterval($interval) : \DateInterval
    {
        if ($interval instanceof DateInterval) {
            return $interval->toInternalDateInterval();
        }
        
        if (is_string($interval)) {
            return new \DateInterval($interval);
        }
        
        if ($interval instanceof \DateInterval) {
            return $interval;
        }
        
        throw new \InvalidArgumentException('Interval must be a string or an instance of DateInterval.');
    }
487725
public function add($interval)
    {
        parent::add($interval);

        if ($interval instanceof DateInterval) {
            if ($interval->invert) { // is negative, then sub
                $this->subMicroseconds($interval->u);
            } else {
                $this->addMicroseconds($interval->u);
            }
        }

        return $this;
    }
1103495
public function withIntervalInHours($intervalInHours)
    {
        $this->validateInterval($intervalInHours);
        $this->interval = $intervalInHours;
        $this->intervalUnit = IntervalUnit::HOUR;

        return $this;
    }
55382
public function setTtl($ttl)
    {
        if (!is_null($ttl)) {
            if (!is_numeric($ttl) || (intval($ttl) < 1)) {
                throw new \InvalidArgumentException(sprintf('Invalid TTL: %s', $ttl));
            }

            $this->ttl = intval($ttl);
        } else {
            $this->ttl = null;
        }

        return $this;
    }
677433
public function setExpiresIn(DateInterval $interval)
    {
        $this->expires = new DateTime();
        $this->expires->add($interval);
        return $this;
    }
720105
public function setMinute( int $value = null ) : Time
   {

      if ( \is_null( $value ) )
      {
         $this->properties[ 'minute' ] = static::CurrentMinute();
         return $this;
      }

      $intValue = \intval( $value );

      if ( $intValue < 0 )
      {
         $this->properties[ 'minute' ] = 0;
      }
      else if ( $intValue > 59 )
      {
         $this->properties[ 'minute' ] = $intValue % 60;
      }
      else
      {
         $this->properties[ 'minute' ] = $intValue;
      }

      return $this;

   }
1067772
protected function _convertUnit($unit)
    {
        if ($unit === 'week') {
            return self::ONE_WEEK;
        }

        if ($unit === 'day') {
            return self::ONE_DAY;
        }

        if ($unit === 'hour') {
            return self::ONE_HOUR;
        }

        if ($unit === 'minute') {
            return self::ONE_MINUTE;
        }

        if ($unit === 'second') {
            return self::ONE_SECOND;
        }

        if ($unit === 'millisecond') {
            return self::ONE_MILLISECOND;
        }

        throw new BuildException("Illegal unit '$unit'");
    }
664206
public function setLifetime($lifetime)
    {
        $lifetime = intval($lifetime);

        if ($lifetime < 1 || $lifetime > 44640) {
            throw new InvalidArgument('Valid value ranges between 1 minute and 31 days given in minutes');
        }

        $this->lifetime = $lifetime;

        return $this;
    }
770729
public function setByHour($value)
    {
        if (!is_integer($value) || $value < 0 || $value > 23) {
            throw new \InvalidArgumentException('Invalid value for BYHOUR');
        }

        $this->byHour = $value;

        $this->canUseBySetPos = true;

        return $this;
    }