briannesbitt/Carbon · error · UnknownUnitException

Unknown unit '$unit'.

Error message

Unknown unit '$unit'.

What it means

Error "Unknown unit '$unit'." thrown in briannesbitt/Carbon.

Source

Thrown at src/Carbon/Traits/Boundaries.php:443

        return $this->setTime($this->hour, $this->minute, $this->second, $millisecond * 1000 + 999);
    }

    /**
     * Modify to start of current given unit.
     *
     * @example
     * ```
     * echo Carbon::parse('2018-07-25 12:45:16.334455')
     *   ->startOf(Unit::Month)
     *   ->endOf(Unit::Week, Carbon::FRIDAY);
     * ```
     */
    public function startOf(Unit|string $unit, mixed ...$params): static
    {
        $ucfUnit = ucfirst($unit instanceof Unit ? $unit->value : static::singularUnit($unit));
        $method = "startOf$ucfUnit";
        if (!method_exists($this, $method)) {
            throw new UnknownUnitException($unit);
        }

        return $this->$method(...$params);
    }

    /**
     * Modify to end of current given unit.
     *
     * @example
     * ```
     * echo Carbon::parse('2018-07-25 12:45:16.334455')
     *   ->startOf(Unit::Month)
     *   ->endOf(Unit::Week, Carbon::FRIDAY);
     * ```
     */
    public function endOf(Unit|string $unit, mixed ...$params): static
    {
        $ucfUnit = ucfirst($unit instanceof Unit ? $unit->value : static::singularUnit($unit));

View on GitHub (pinned to b13f05955d)

When it happens

Trigger: Thrown at src/Carbon/Traits/Boundaries.php:443 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of briannesbitt/Carbon@b13f05955d (2026-08-17). Data as JSON: /api/errors/f3e61641655310c2. Report an issue: GitHub.