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: 2017-03-19 11:04 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: Open Package: Date/time related
PHP Version: 7.1 OS: ALL
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: glavic at gmail dot com
New email:
PHP Version: OS:

 

 [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);`
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 19 09:01:29 2019 UTC