src/Carbon/Traits/Date.php
public function setUnit($unit, $value = null)
    {
        $unit = static::singularUnit($unit);
        $dateUnits = ['year', 'month', 'day'];
        if (in_array($unit, $dateUnits)) {
            return $this->setDate(...array_map(function ($name) use ($unit, $value) {
                return $name === $unit ? $value : $this->$name;
            }, $dateUnits));
        }

        $units = ['hour', 'minute', 'second', 'micro'];
        if ($unit === 'millisecond' || $unit === 'milli') {
            $value *= 1000;
            $unit = 'micro';
        } elseif ($unit === 'microsecond') {
            $unit = 'micro';
        }

        return $this->setTime(...array_map(function ($name) use ($unit, $value) {
            return $name === $unit ? $value : $this->$name;
        }, $units));
    }
public function setUnit($unit, $value = null)
    {
        $unit = static::singularUnit($unit);
        $dateUnits = ['year', 'month', 'day'];
        if (in_array($unit, $dateUnits)) {
            return $this->setDate(...array_map(function ($name) use ($unit, $value) {
                return $name === $unit ? $value : $this->$name;
            }, $dateUnits));
        }

        $units = ['hour', 'minute', 'second', 'micro'];
        if ($unit === 'millisecond' || $unit === 'milli') {
            $value *= 1000;
            $unit = 'micro';
        } elseif ($unit === 'microsecond') {
            $unit = 'micro';
        }

        return $this->setTime(...array_map(function ($name) use ($unit, $value) {
            return $name === $unit ? $value : $this->$name;
        }, $units));
    }
public function setUnit ( $ unit , $ value = null ) { $ unit = static :: singularUnit ( $ unit ) ; $ dateUnits = [ 'year' , 'month' , 'day' ] ; if ( in_array ( $ unit , $ dateUnits ) ) { return $ this -> setDate ( ... array_map ( function ( $ name ) use ( $ unit , $ value ) { return $ name === $ unit ? $ value : $ this -> $ name ; } , $ dateUnits ) ) ; } $ units = [ 'hour' , 'minute' , 'second' , 'micro' ] ; if ( $ unit === 'millisecond' || $ unit === 'milli' ) { $ value *= 1000 ; $ unit = 'micro' ; } elseif ( $ unit === 'microsecond' ) { $ unit = 'micro' ; } return $ this -> setTime ( ... array_map ( function ( $ name ) use ( $ unit , $ value ) { return $ name === $ unit ? $ value : $ this -> $ name ; } , $ units ) ) ; }
Set specified unit to new given value.

@param string $unit  year, month, day, hour, minute, second or microsecond
@param int    $value new value for given unit

@return static
Set specified unit to new given value .