Skip to content

Stdlib: DateTime::createFromTimestamp() float $timestamp — fractional seconds truncated (extends #5973, ext/date/php_date.c) #9984

Closed

Description

@PurHur

Category

stdlib · php-src-strict · extends #5973

Problem

DateTime::createFromTimestamp() / DateTimeImmutable::createFromTimestamp() exist (#5973) for int timestamps, but PHP 8.4 accepts int|float and preserves subsecond precision.

VM lowers the argument via VmMath::parseIntBuiltinArg() in DateTimeCreateFromTimestamp.php, so 1700000000.5 formats as 1700000000.000000 instead of 1700000000.500000.

php-src reference

Repro

test/repro/datetime_create_from_timestamp_float.php:

<?php
date_default_timezone_set('UTC');
$dt = DateTime::createFromTimestamp(1_700_000_000.5);
echo $dt->format('U.u'), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/datetime_create_from_timestamp_float.php'
# VM today: 1700000000.000000
# php-src 8.4: 1700000000.500000

Implementation hints (PHP-in-PHP)

  • Accept int|float in DateTimeCreateFromTimestamp / DateTimeImmutableCreateFromTimestamp
  • Extend DateTimeSupport::initDateTimeFromTimestamp() to split integer seconds + fractional part into date object fields (mirror php-src timelib)
  • Update compliance datetime_create_from_timestamp.phpt with float case
  • JIT/AOT: same semantics when methods are lowered

Scope

  • lib/VM/Builtin/DateTimeCreateFromTimestamp.php
  • lib/VM/Builtin/DateTimeImmutableCreateFromTimestamp.php
  • lib/VM/DateTimeSupport.php

Done when

  • Float repro prints 1700000000.500000 (UTC)
  • Int timestamps unchanged
  • Invalid types still TypeError per php-src
  • Compliance .phpt extended

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/datetime_create_from_timestamp_float.php'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php vendor/bin/phpunit test/compliance/cases/stdlib/datetime_create_from_timestamp.phpt'

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 19, 2026
  2. PurHur commented on Jul 4, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-a — starting this run

  3. PurHur commented on Jul 4, 2026

    @PurHur
    OwnerAuthor

    Merged via #15782.

    Verification (Docker):

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/datetime_create_from_timestamp_float.php'
    # 1700000000.500000
    # 1700000000.500000
    
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php vendor/bin/phpunit --filter datetime_create_from_timestamp test/compliance/VMTest.php'
    # OK (1 test, 1 assertion)
    

    Float timestamps now split into epoch seconds + microseconds in DateTimeSupport::splitTimestampNumber(); builtins accept int|float via VmMath::parseNumberBuiltinArg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions