From:
Operating system: *
PHP version: 5.3.2
Package: Date/time related
Bug Type: Feature/Change Request
Bug description:Native interface for date/time functions
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 bug report at http://bugs.php.net/bug.php?id=51451&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51451&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51451&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51451&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51451&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51451&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51451&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51451&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51451&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51451&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51451&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51451&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51451&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51451&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51451&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51451&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51451&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51451&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51451&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51451&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51451&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51451&r=mysqlcfg