php.net |  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
Votes:14
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-09-12 08:51 UTC] glavic at gmail dot com
Description:
------------
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:
http://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators

Test script:
---------------
<?php
$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: http://3v4l.org/b4n9j

Expected result:
----------------
bool(true)

bool(true) # with correct offset ofc

Actual result:
--------------
bool(true) 

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

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-19 11:04 UTC] heiglandreas@php.net
-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] derick@php.net
-Status: Open +Status: Wont fix
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 13:01:30 2024 UTC