|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-03-31 23:44 UTC] johannes@php.net
-Status: Open
+Status: Bogus
[2010-03-31 23:44 UTC] johannes@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 22:00:02 2025 UTC |
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 ?>