Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64232 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96362 invoked from network); 10 Dec 2012 15:30:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2012 15:30:26 -0000 Received: from [127.0.0.1] ([127.0.0.1:9644]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 7E/86-60401-21006C05 for ; Mon, 10 Dec 2012 10:30:26 -0500 Authentication-Results: pb1.pair.com smtp.mail=nnefedov@imhonet.ru; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nnefedov@imhonet.ru; sender-id=pass Received-SPF: pass (pb1.pair.com: domain imhonet.ru designates 78.47.38.178 as permitted sender) X-PHP-List-Original-Sender: nnefedov@imhonet.ru X-Host-Fingerprint: 78.47.38.178 mail.imhoclub.ru Linux 2.6 Received: from [78.47.38.178] ([78.47.38.178:35047] helo=mail.imhoclub.ru) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/76-60401-DBCF5C05 for ; Mon, 10 Dec 2012 10:16:15 -0500 Received: from mail.imhoclub.ru (localhost [127.0.0.1]) by mail.imhoclub.ru (Postfix) with ESMTP id 34629CC216 for ; Mon, 10 Dec 2012 19:16:11 +0400 (MSK) Received: by mail.imhoclub.ru (Postfix, from userid 1002) id 29369CC23C; Mon, 10 Dec 2012 19:16:11 +0400 (MSK) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.imhoclub.ru X-Spam-Level: X-Spam-Status: No, score=-5.4 required=7.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.3.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -5.0 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.6 AWL AWL: From: address is in the auto white-list Received: from debian-nnefedov.local (unknown [46.38.35.218]) by mail.imhoclub.ru (Postfix) with ESMTPA id AFB3BCC216 for ; Mon, 10 Dec 2012 19:16:10 +0400 (MSK) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Date: Mon, 10 Dec 2012 19:18:06 +0400 To: "internals@lists.php.net" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: Imhonet Message-ID: User-Agent: Opera Mail/12.11 (Linux) X-Virus-Scanned: ClamAV using ClamSMTP Subject: DateTime improvement From: nnefedov@imhonet.ru ("Nikita Nefedov") So there had been at least two or three messages (subjects) about DateTime object and everytime there was this problem - people tend to take DateTime object as mutable object and it really is. As long as we know, it's not so good - date is immutable by nature. I don't want to write here why it's so, I will just throw this link: http://www.ibm.com/developerworks/java/library/j-jtp02183/index.html I don't want to change any existing functionality, because some people already use it, but I just wanted to point out that current DateTime class is forcing people to think about it as mutable. My main concerns are DateTime#add() and DateTime#sub(). The problem is - they both change current object and return it. I think we could add methods to DateTime like add() and sub(), let's say plus() and minus(), but they would behave differently in the way that they would return new DateTime objects and won't change current object. Here's gist to make it clear: https://gist.github.com/4250785 Also, there's methods compareTo, createFromTimestamp and createFromDay, it could be another proposal. I think we are very often create DateTime objects just from timestamp or year-month-day. So we could introduce this methods that could not rely on timelib's parsing, and instead just take numbers directly. And I think DateTime lack comparing method. For now I can compare DateTime objects only by getting their timestamps, but I though that the idea of DateTime was to go away from using timestamps and instead use well thought out api. Anyway, I think this three methods should be considered as another proposal (because they are solve different problems). Even if this proposal doesn't go far, I think we should do something with DateTime. I think I'm going to create user-land library for dealing with some of this problems. But if it pass, I will make patch.