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

 ID:                 54660
 Updated by:         fel...@php.net
 Reported by:        giorgio dot liscio at email dot it
 Summary:            DateInterval Fatal error: main(): Unknown property
                     (h)
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            Date/time related
 Operating System:   any?
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

It's working fine in 5.3, 5.4 and trunk.


Previous Comments:
------------------------------------------------------------------------
[2011-05-04 21:16:56] giorgio dot liscio at email dot it

update: on latest trunk first snippet work good (-1 is obtained)

------------------------------------------------------------------------
[2011-05-04 17:53:08] giorgio dot liscio at email dot it

reopened feedback provided

------------------------------------------------------------------------
[2011-05-04 17:51:56] giorgio dot liscio at email dot it

hi derick, thank you, i will try! read my suggests anyway!!

------------------------------------------------------------------------
[2011-05-04 17:50:23] giorgio dot liscio at email dot it

please read carefully because DateInterval is really ambiguous

since it is just introduced in php5.3 can be modified before lot of users 
starts to use this lib



what is ambiguous:



i can do, for example: $datetimeobj->diff($datetimeobj2, FALSE); to obtain a 
dateinterval with negative values ( read: $obj->h = -1 )



but i can't do DateInterval::createFromDateString("-1 hour");



i don't know how ambiguity will be resolved, but my suggests are:



SOLUTION 1

{



- drop ->invert and allow negative values to ->y ->m ->d ->h ->i ->s



->diff() second parameter works good now



- add a method to dateInterval to invert all values ( ->invertAll() ) that not 
sets ->invert, but inverts single properties ( $this->h = $this->h * -1; )



- modify constructor to match the new logic

iso8601 seems do not allow negative single values, but can be good to have a 
constructor like this:

public DateInterval::__construct( string $interval_spec , bool $invertAllValues)

that converts P2Y4DT6H8M in an hypothetically P  -2Y  -4D  T  -6H  -8M



- drop ->add and ->sub from DateTime class and implement ->change that offers 
same functionality and more when used with negative intervals and positive 
intervals



}



SOLUTION 2

{



DateInterval properties ymdhis should be always >=0



- DateTime->diff() should not never returns an object with negative values, but 
should flag inverted intervals using ->invert = TRUE



- drop ->add and ->sub and implement ->change that offers same functionality



$a = DateInterval("P1Y");

$datetime->change($a); // add

$a->invert = true;

$datetime->change($a) // subtract



}



i sincerely prefer the first version because mixing negative and positive 
single values would be nice (DateIntervall::createFromDateString("1 year 1 
month -10 days"))

but i will like any solution that resolves the ambiguities of this class

------------------------------------------------------------------------
[2011-05-04 17:19:09] der...@php.net

Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

This works fine for me:



derick@whisky:~$ php -v

PHP 5.3.7-dev (cli) (built: May  4 2011 09:16:17) (DEBUG)



<?php

$a = \DateInterval::createFromDateString("1 month 1 hour");

echo $a->h; // ok

        

$a = \DateInterval::createFromDateString("1 month 0 hour");

echo $a->h; // ok

        

$a = \DateInterval::createFromDateString("1 month -1 hour");

echo $a->h; // fatal error, ->h is not defined

?>

10-1

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=54660


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

Reply via email to