Skip to content

Stdlib: date_sunrise()/date_sunset() — solar position helpers missing (ext/date/php_date.c) #6137

Description

@PurHur

Category

stdlib

Problem

Procedural solar-position helpers date_sunrise() and date_sunset() compute local sunrise/sunset timestamps from geographic coordinates. They live in ext/date alongside date() / strtotime() but are not registered here (function_exists('date_sunrise') → false, verified Jun 2026).

Related procedural gaps: #3292 (strtotime/mktime), #3504 (timezone introspection).

php-src reference

  • ext/date/php_date.c — PHP_FUNCTION(date_sunrise), PHP_FUNCTION(date_sunset)
  • ext/date/lib/astro.c — solar algorithm (shared with date_sun_info())
  • Constants: SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, SUNFUNCS_RET_DOUBLE

Repro (failure today)

<?php
date_default_timezone_set('UTC');
$ts = date_sunrise(mktime(0, 0, 0, 6, 21, 2026), SUNFUNCS_RET_TIMESTAMP, 51.5, -0.1, 90, 0);
echo is_int($ts) || is_float($ts) ? 'ok' : 'fail', "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Runtime Output
Zend PHP 8.x ok (numeric timestamp)
bin/vm.php Call to undefined function date_sunrise()

Scope (this repo)

Area Path Notes
Stdlib ext/date/date_sunrise.php, date_sunset.php or ext/standard/ v1 may delegate to host date_sunrise in VM
Constants ext/date/DateConstants.php SUNFUNCS_*
Tests test/compliance/cases/date/sunrise_sunset.phpt Compare numeric output to Zend (tolerance OK)
JIT/AOT VM-first v1 Document deferral

Defer date_sun_info() OOP to phase 2 (same astro.c).

Done when

  • Repro prints ok on VM with timestamp within ±60s of Zend on same inputs
  • SUNFUNCS_RET_STRING and SUNFUNCS_RET_DOUBLE modes supported
  • Invalid latitude/longitude → false like Zend
  • ./script/ci-fast.sh --filter date_sunrise green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter date_sunrise'

Links

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 5, 2026
  2. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#6137: date_sunrise/date_sunset VM builtins via VmDate host bridge).

  3. PurHur commented on Jun 11, 2026

    @PurHur
    OwnerAuthor

    Merged via #7965.

    Verification

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php test/repro/maintainer_date_sunrise_sunset.php
    vendor/bin/phpunit --filter date_sunrise_sunset_basic
    '

    VM repro: rise_ok/set_ok + timestamps 1782013676/1782072990 matching Zend.
    PHPUnit: OK (2 tests, 2 assertions).

    PHP path: ext/standard/VmDate.php, date_sunrise.php, date_sunset.php, VmDateSunFunc.php
    C runtime: no new C (phpc_progress.c only remains frozen ABI).

  4. PurHur commented on Jun 12, 2026

    @PurHur
    OwnerAuthor

    Merged via #8125.

    Implementation: ext/standard/JitDateSunFunc.php — compile-time literal baking over VmDateSunNative (php-src ext/date/php_date.c + ext/date/lib/astro.c). Supporting fixes: compileTimeFloat propagation through unary - and temporary boxing (lib/JIT.php, JitUnaryMinus.php, Variable.php).

    Verification (Docker):

    • vendor/bin/phpunit --filter date_sunrise_sunset test/compliance/VMTest.php — OK (VM + JIT PHPT)
    • vendor/bin/phpunit --filter date_sunrise_sunset test/aot/AotTest.php — OK (AOT link + execute)
    • php bin/compile.php -o /tmp/sun … with date_sunrise(1782000000, 0, 51.5, -0.1, 90.0, 0.0) → 1782013676
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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions