Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62666 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51143 invoked from network); 2 Sep 2012 11:33:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2012 11:33:23 -0000 Authentication-Results: pb1.pair.com header.from=derick@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=derick@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 82.113.146.227 as permitted sender) X-PHP-List-Original-Sender: derick@php.net X-Host-Fingerprint: 82.113.146.227 xdebug.org Linux 2.6 Received: from [82.113.146.227] ([82.113.146.227:36591] helo=xdebug.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/A6-17065-30443405 for ; Sun, 02 Sep 2012 07:33:23 -0400 Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 79602DE13E; Sun, 2 Sep 2012 12:33:20 +0100 (BST) Date: Sun, 2 Sep 2012 12:33:20 +0100 (BST) X-X-Sender: derick@whisky.home.derickrethans.nl To: Will Fitch cc: PHP Developers Mailing List In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] RFC for Adding __toString to DateTime From: derick@php.net (Derick Rethans) On Sun, 2 Sep 2012, Will Fitch wrote: > On Sat, Sep 1, 2012 at 4:54 PM, Derick Rethans wrote: > > > On Sat, 1 Sep 2012, Will Fitch wrote: > > > > > I would like to officially introduce an RFC with a patch to implement > > > __toString to DateTime. This is a commonly requested feature that goes > > > unanswered mostly because of the inability to agree on a default pattern. > > > > > > In short, the patch uses the ISO-8601 format as the default pattern. The > > > pattern may be changed via setDefaultPattern and > > date_default_pattern_set, > > > as explained in the RFC. > > > > The default should most definitely not be ISO-8601 - as it's a lossy > > format. > > > > In terms of lossy transmission/storage, what concerns in regards to the > pattern are you referring to? $ php -r 'echo date_create()->format( DateTime::ISO8601 );' 2012-09-02T12:26:17+0100 ^^^^^ is the lossless bit. It tells you nothing about the timezone. This is why var_dump(date_create()) has: public $timezone => string(13) "Europe/London" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > ISO-8601 is only output *if* there is no pre-set pattern provided. So > in essance, in essance? > > > The link to the RFC and patch are here: > > > https://wiki.php.net/rfc/datetime_tostring. > > > > > Methods Added > > > > > > void DateTime::setDefaultPattern(string $pattern) > > > string DateTime::getDefaultPattern(void) > > > > This should be descriptive. You are *only* dealing with __toString here. > > Hence the method names should reflect that: > > > > void DateTime::setToStringFormat(string $pattern) > > string DateTime::getToStringFormat(void) > > > > However, I still don't believe this belongs in the class at all. It is > > rather trivial to do this in userland: > > > > class MyDateTime extends DateTime { > > static $format = "... some format..."; > > function __toString() { return $this->format(DateTime::$format); } > > } > > > > There, 4 lines. And no quaralling about formats or naming. > > I'm definitely not sold on any naming convention or format, and I don't see > any quarrelling going on. The purpose of the RFC is to come up with a > solution and discuss implementation. I don't expect any quarrels for > something this simple. Right, it's so simple that it can be done in userland in 4 lines of code. I don't want to add this. cheers, Derick -- http://derickrethans.nl | http://xdebug.org Like Xdebug? Consider a donation: http://xdebug.org/donate.php twitter: @derickr and @xdebug Posted with an email client that doesn't mangle email: alpine