Skip to content

DatePeriod::__construct(string $isostr) - ISO string does not accept time zone offsets #1291

@aeno

Description

@aeno

Regarding https://www.php.net/manual/en/dateperiod.construct.php


The documentation says that ISO8601 repeating interval strings are supported, but does not reveal that time zone offsets are not supported.

Calling the documentation's example (with Z indicating UTC timezone) works:

$iso = 'R4/2012-07-01T00:00:00Z/P7D';
$period = new DatePeriod($iso);

The same string with an one-hour offset throws an exception:

$iso = 'R4/2012-07-01T00:00:00+0100/P7D';
$period = new DatePeriod($iso);
// throws "Uncaught Exception: DatePeriod::__construct(): Unknown or bad format (R4/2012-07-01T00:00:00+0100/P7D)"

Valid variations of the offset part throw an exception as well:

$iso = 'R4/2012-07-01T00:00:00+01/P7D';
$iso = 'R4/2012-07-01T00:00:00+01:00/P7D';

This fact should be included in the notes section

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions