{ $unit = \strtolower(\substr($unit, 3)); } if (\in_array($unit, static::$units, \true)) { return $this->setUnit($unit, ...$parameters); } if ($action === 'add' || $action === 'sub') { $unit = \substr($unit, 3); if (\str_starts_with($unit, 'Real')) { $unit = static::singularUnit(\substr($unit, 4)); return $this->{"{$action}RealUnit"}($unit, ...$parameters); } if (\preg_match('/^(Month|Quarter|Year|Decade|Century|Centurie|Millennium|Millennia)s?(No|With|Without|WithNo)Overflow$/', $unit, $match)) { $unit = $match[1]; $overflow = $match[2] === 'With'; } $unit = static::singularUnit($unit); } if (static::isModifiableUnit($unit)) { return $this->{"{$action}Unit"}($unit, $parameters[0] ?? 1, $overflow); } $sixFirstLetters = \substr($unit, 0, 6); $factor = -1; if ($sixFirstLetters === 'isLast') { $sixFirstLetters = 'isNext'; $factor = 1; } if ($sixFirstLetters === 'isNext') { $lowerUnit = \strtolower(\substr($unit, 6)); if (static::isModifiableUnit($lowerUnit)) { return $this->copy()->addUnit($lowerUnit, $factor, \false)->isSameUnit($lowerUnit, ...$parameters); } } if ($sixFirstLetters === 'isSame') { try { return $this->isSameUnit(\strtolower(\substr($unit, 6)), ...$parameters); } catch (BadComparisonUnitException $exception) { // Try next } } if (\str_starts_with($unit, 'isCurrent')) { try { return $this->isCurrentUnit(\strtolower(\substr($unit, 9))); } catch (BadComparisonUnitException|BadMethodCallException $exception) { // Try next } } if (\str_ends_with($method, 'Until')) { try { $unit = static::singularUnit(\substr($method, 0, -5)); return $this->range($parameters[0] ?? $this, $parameters[1] ?? 1, $unit); } catch (InvalidArgumentException $exception) { // Try macros } } return static::bindMacroContext($this, function () use(&$method, &$parameters) { $macro = $this->getLocalMacro($method); if (!$macro) { foreach ([$this->localGenericMacros ?: [], static::getGenericMacros()] as $list) { foreach ($list as $callback) { try { return $this->executeCallable($callback, $method, ...$parameters); } catch (BadMethodCallException $exception) { continue; } } } if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) { throw new UnknownMethodException($method); } return null; } return $this->executeCallable($macro, ...$parameters); }); } }