Skip to content

Stdlib: DatePeriod OOP — date range iteration (ext/date/php_date.c parity) #3633

@PurHur

Description

@PurHur

Category

stdlib

Problem

DatePeriod is a core ext/date class for iterating date ranges (new DatePeriod($start, $interval, $end)). It is not registered — class_exists('DatePeriod') is false under bin/vm.php. Calendar/scheduling code and Symfony-style date utilities depend on it.

Follow-up to #3072 / #3162 (DateTime / DateInterval); DatePeriod requires both plus range iteration semantics.

php-src reference

Repro (failure today)

<?php
$start = new DateTime('2024-01-01');
$end   = new DateTime('2024-01-04');
$step  = new DateInterval('P1D');
foreach (new DatePeriod($start, $step, $end) as $dt) {
    echo $dt->format('Y-m-d'), "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
# class DatePeriod not found (after #3072 DateTime exists)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php repro.php'
# Zend:
# 2024-01-01
# 2024-01-02
# 2024-01-03

Scope (this repo)

Module Path
VM OOP ext/standard/VmDate.php or new ext/date/ module — DatePeriod + Iterator
Prerequisite #3072 DateTime, #3162 DateInterval
Foreach #3234 Traversable/Iterator foreach if object iteration not generic yet
Registration ext/standard/Module.php or dedicated date module
Tests test/compliance/cases/stdlib/date_period.phpt
Matrix docs/capabilities-syntax.md DateTime row extension

Done when

  • Repro prints three dates on VM matching Zend (exclusive end boundary per php-src)
  • DatePeriod implements Iterator / Traversable; foreach works
  • Recurrence count form new DatePeriod($start, $interval, $recurrences) matches Zend
  • ./script/ci-fast.sh --filter date_period green

Related

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