cakephp / chronos

A standalone DateTime library originally based off of Carbon

Home Page:http://book.cakephp.org/chronos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FactoryTrait::create() and createFromTime() missing microseconds

othercorey opened this issue · comments

These interfaces seem to be missing microsecond parameters.

I assume there will be backwards compatibility issues, but this seems like a strange omission.

Since $tz has no type, it could accept the microsecond value, but it will hit a runtime failure instead of silently converting/ignoring.

The type hints in 2.x should ensue any internal code is using it right.

@param \DateTimeZone|string|null $tz The DateTimeZone object or timezone name the new instance should use.

    public static function create(
        ?int $year = null,
        ?int $month = null,
        ?int $day = null,
        ?int $hour = null,
        ?int $minute = null,
        ?int $second = null,
        $tz = null
    ): ChronosInterface {

Since $tz has no type, it could accept the microsecond value, but it will hit a runtime failure instead of silently converting/ignoring.

You could count the number of arguments and argument types to determine whether or not you have a timezone or a microsecond. The timezone should be a string or a DateTimeZone while microseconds should be an integer.

The backwards compatibility issues aren't as severe if we include them in the 2.x branch as it is not yet stable so now is a great time to make this change.

PR open