Edit report at http://bugs.php.net/bug.php?id=51451&edit=1
ID: 51451 Updated by: [email protected] Reported by: kenaniah at gmail dot com Summary: Native interface for date/time functions -Status: Open +Status: Bogus Type: Feature/Change Request Package: Date/time related Operating System: * PHP Version: 5.3.2 New Comment: As discussed on IRC: This is a very special case, not comparable to Countable and brings very little benefit. Previous Comments: ------------------------------------------------------------------------ [2010-03-31 23:26:57] kenaniah at gmail dot com Description: ------------ I would love to see interfaces defined in core that would allow any implementing object to be passed parameters to date/time functions when applicable, very similar to the way Countable allows any implementing object to be count()'ed. For example, an interface such as Timestampable may allow implementing objects a method by which they may produce a timestamp for usage in all PHP core date/time functions that accept a timestamp parameter. The interface would define a single method called timestamp() expected to return an integer value representing the timestamp to be used. Any core PHP date/time functions that previously accepted only integers for timestamps should be extended to allow for objects that implement the Timestampable interface as well. Finally, DateTime should implement this interface natively, allowing it to be passed directly to functions such as date() without modification. Test script: --------------- <?php date_default_timezone_set('America/Los_Angeles'); $string = "2008-10-14 6:24 PM America/New_York"; $date = new DateTime($string); print $date->format("c"); //2008-10-14T18:24:00-04:00 print date("c", strtotime($string)); //2008-10-14T15:24:00-07:00 print date("c", $date); //2008-10-14T15:24:00-07:00 class Foo implements Timestampable { function timestamp(){ return 1270000; //Returns timestamp to be used } } $obj = new Foo; print date("c", $obj); //1970-01-15T08:46:40-08:00 ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51451&edit=1
