ID:               45545
 Comment by:       tj at systisoft dot com
 Reported By:      tj at systisoft dot com
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: All
 PHP Version:      5.3CVS-2008-07-17 (CVS)
 New Comment:

If you decide to keep the limit you should move that to documentation I
think :).


Previous Comments:
------------------------------------------------------------------------

[2008-07-17 16:17:58] tj at systisoft dot com

Description:
------------
If you want to create a DateInterval of 36000 seconds (10 hours) the
creation will fail because you have a limit of 4 chars in the format
accepted by the constructor.

Up to days you can do the "carry over" calculation for yourself (But
not for months or years), but if you get an offset in seconds from a
source you cannot control it would be nice if you could just do:

$date->add(new DateInterval('PT' . $seconds . 'S'));

Now you have to check if seconds exceeds the limit an if it exceeds the
limit you have to recalculate yourself. That is not nice from a user
point of view.

Reproduce code:
---------------
$d = new DateTime('2008-01-01 10:00:00 UTC');
$d->add(new DateInterval('PT36000S'));
echo $d->format(DATE_ISO8601), PHP_EOL;

Expected result:
----------------
2008-01-01T20:00:00+0000

Actual result:
--------------
PHP Fatal error:  Uncaught exception 'Exception' with message
'DateInterval::__construct(): Unknown or bad format (PT36000S)' in
/Users/tobias/test.php:2
Stack trace:
#0 /Users/tobias/test.php(2): DateInterval->__construct('PT36000S')
#1 {main}
  thrown in /Users/tobias/test.php on line 2

Fatal error: Uncaught exception 'Exception' with message
'DateInterval::__construct(): Unknown or bad format (PT36000S)' in
/Users/tobias/test.php:2
Stack trace:
#0 /Users/tobias/test.php(2): DateInterval->__construct('PT36000S')
#1 {main}
  thrown in /Users/tobias/test.php on line 2


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45545&edit=1

Reply via email to