php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51451 Native interface for date/time functions
Submitted: 2010-03-31 23:26 UTC Modified: 2010-03-31 23:44 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: kenaniah at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.2 OS: *
Private report: No CVE-ID: None
 [2010-03-31 23:26 UTC] 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

?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-31 23:44 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-03-31 23:44 UTC] johannes@php.net
As discussed on IRC: This is a very special case, not comparable to Countable and brings very little benefit.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 04:01:32 2024 UTC