|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65657 DatePeriod doesn't accept valid ISO-8601 formats (timezone problem)
Submitted: 2013-09-12 08:51 UTC Modified: 2021-04-07 09:29 UTC
Avg. Score:4.6 ± 0.8
Reproduced:14 of 14 (100.0%)
Same Version:12 (85.7%)
Same OS:11 (78.6%)
From: glavic at gmail dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 7.1 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: glavic at gmail dot com
New email:
PHP Version: OS:


 [2013-09-12 08:51 UTC] glavic at gmail dot com
The ISO-8601 states the following: "The offset from UTC is given in the format ±[hh]:[mm], ±[hh][mm], or ±[hh].". But DatePeriod accepts only $iso formats that are in UTC (flag Z). See test script.

I have tried all possible combinations to set timezone correctly, but no success:

Test script:
$iso = 'R2/2013-09-09T12:00:15Z/P1D';
$periods = new DatePeriod($iso);
var_dump( is_object($periods) );

$iso = 'R2/2013-09-09T12:00:15+02:00/P1D';
$periods = new DatePeriod($iso);
var_dump( is_object($periods) );

Run this on multiple PHP versions:

Expected result:

bool(true) # with correct offset ofc

Actual result:

Fatal error: Uncaught exception 'Exception' with message 'DatePeriod::__construct(): Unknown or bad format (R2/2013-09-09T12:00:15+02:00/P1D)' in ...


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-19 11:04 UTC]
-PHP Version: Irrelevant +PHP Version: 7.1
 [2017-06-26 23:02 UTC] jc at unternet dot net
I'm working on it. meanwhile you can use:

`$periods = new DatePeriod(new DateTime("2013-09-09T12:00:15+02:00"), new DateInterval("P1D"), 2);`
 [2021-04-07 09:29 UTC]
-Status: Open +Status: Wont fix
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 27 14:03:54 2023 UTC