Skip to content

Time\Duration - #23073

Merged
TimWolla merged 5 commits into
php:masterfrom
TimWolla:time-duration
Aug 7, 2026
Merged

Time\Duration#23073
TimWolla merged 5 commits into
php:masterfrom
TimWolla:time-duration

Conversation

@TimWolla

@TimWolla TimWolla commented Aug 5, 2026

Copy link
Copy Markdown
Member

Comment thread ext/date/config0.m4 Outdated
Comment thread ext/date/time_duration.c
Comment thread ext/date/php_date_time_duration.c Outdated
Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/php_date_time_duration.c Outdated
Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/tests/time/duration/fromNanoseconds_64.phpt Outdated
Comment thread ext/date/php_date_time_duration.c Outdated
Comment thread ext/date/time_duration.c
Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/php_date_time_duration.c Outdated

php_date_time_duration *original = Z_DATE_TIME_DURATION_P(ZEND_THIS);
php_date_time_duration *additional = php_date_time_duration_from_obj(duration);
php_date_time_duration *new = Z_DATE_TIME_DURATION_P(return_value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When either original or additional has recount==1, it may be possible to reuse it?

Comment thread ext/date/time_duration.c Outdated
@TimWolla
TimWolla force-pushed the time-duration branch 8 times, most recently from ebb8107 to 5f203d8 Compare August 5, 2026 20:09
@TimWolla TimWolla added the RFC label Aug 5, 2026
@TimWolla
TimWolla requested review from arnaud-lb and derickr August 5, 2026 20:16
@TimWolla
TimWolla force-pushed the time-duration branch 2 times, most recently from 89e45ab to 6390166 Compare August 5, 2026 20:43
Comment thread ext/date/tests/time/duration/methods/add.phpt Outdated
Comment thread ext/date/tests/time/duration/methods/div.phpt Outdated
Comment thread ext/date/tests/time/duration/methods/mul.phpt Outdated
Comment thread ext/date/php_time.c
Comment thread ext/date/php_time.c Outdated
Comment thread ext/date/php_time.h Outdated
Comment thread ext/date/php_time.h Outdated
@TimWolla
TimWolla force-pushed the time-duration branch 2 times, most recently from 95eee76 to a2a58e7 Compare August 6, 2026 08:23
Comment thread ext/date/tests/time/duration/methods/fromIso8601DurationString.phpt Outdated
Comment thread ext/date/lib/duration.c
Comment thread ext/date/php_date.h Outdated
Comment thread ext/date/php_time.h
Comment thread ext/date/time_duration.c
Comment thread ext/date/time_duration.c
Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/time_duration.c

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me otherwise

Comment thread ext/date/time_duration.c Outdated
Comment thread ext/date/time_duration.c
Comment thread ext/date/time_duration.c Outdated
nicolas-grekas pushed a commit to nyamsprod/polyfill that referenced this pull request Aug 7, 2026
Runs the phpt tests of php-src (php/php-src#23073) unmodified against the
polyfill, and fixes the divergences that are left:

 * use the native ZPP wording for the multiplyBy()/divideBy() argument errors,
   and reject a negative divisor with ValueError instead of DivisionByZeroError
 * detect the nanoseconds overflow of multiplyBy(), which turned into
   "TypeError: ... must be of type int, float given"
 * reject "PT1HS" and "PTS", which the native parser does not accept
 * validate $nanoseconds before the range of $seconds in fromSeconds()
 * report the native range error in fromMinutes()/fromHours()/fromMicroseconds()/
   fromMilliseconds() and when parsing an ISO-8601 duration
 * forbid dynamic properties, as the native readonly class does

The range and the sign of zero durations are now enforced in a single place,
so that no operation can return a Duration that breaks the class invariants.

On the test side, the phpt files are byte-identical to php-src, except
helper.inc which cannot use the syntax of PHP >= 8.5, and new.phpt which is
covered by DurationTest since a userland class cannot reject
ReflectionClass::newInstanceWithoutConstructor(). DurationTest now runs on
PHP >= 8.6 too, so its expectations are checked against the native class.

Also adds the subtree split, moves the classmap entry next to the other 8.6
polyfills and ignores the temporary files written by PhptTest.
TimWolla and others added 5 commits August 7, 2026 11:09
…om*()`

This is useful for patterns like the following:

    for (;;) {
        $watchers = $poll->wait(Time\Duration::fromSeconds(1));
        // …
    }

which is repeatedly creating identical duration objects for every loop
iteration.
This will allow polyfills to more easily consume the upstream tests.
@TimWolla TimWolla removed the ABI break label Aug 7, 2026
@TimWolla
TimWolla merged commit 1cf4623 into php:master Aug 7, 2026
18 checks passed
@TimWolla
TimWolla deleted the time-duration branch August 7, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants