Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64219 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68108 invoked from network); 10 Dec 2012 12:22:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2012 12:22:09 -0000 Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-la0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:50361] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6A/71-60401-FE3D5C05 for ; Mon, 10 Dec 2012 07:22:08 -0500 Received: by mail-la0-f42.google.com with SMTP id s15so2005596lag.29 for ; Mon, 10 Dec 2012 04:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=/9+Hx0V/x8sFNXi3J0J7UfteHMZVh+oUYK8x2Kuy0Zo=; b=fe67OLXmouWRMQsC0QSMPcrgZG6hdO62ZG6Z1TRsajooe7W5V+z4Goe/4c24AyeL9t 5FXiGLRgKIzzahmAWUPDDABO95QhO9apMFAXK3396HqzofuEUgdM+sCgntEYRgKx05iw GT7tmgzaihcyS7cw0WiIiOFO1JI0IdbAr/tTZKKaWHrKzahmH9GyvoblOVEn7fpJ6SQj aOErovWI7leTT9tIqTBAXWeVFxdHyROQ68l5eTGrLTwwSJoEnT49B7SmlfruBijspYlp D4ERy1bTJFwc0s6oGYwPM6LeH7hFQdA3dD5QnCWgqQXIdxJz5adTLOL/PHF659JgVVNX jgvw== Received: by 10.112.88.97 with SMTP id bf1mr6096815lbb.64.1355142124829; Mon, 10 Dec 2012 04:22:04 -0800 (PST) Received: from debian-nnefedov.local ([46.38.35.218]) by mx.google.com with ESMTPS id sr6sm4728840lab.4.2012.12.10.04.22.03 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 10 Dec 2012 04:22:03 -0800 (PST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <4ED7146272E04A47B986ED49E771E347BB362B68DE@Ikarus.ameusgmbh.intern> Date: Mon, 10 Dec 2012 16:23:58 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: <4ED7146272E04A47B986ED49E771E347BB362B68DE@Ikarus.ameusgmbh.intern> User-Agent: Opera Mail/12.11 (Linux) Subject: Re: [PHP-DEV] Improve DateTime Class From: inefedor@gmail.com ("Nikita Nefedov") On Mon, 10 Dec 2012 16:09:36 +0400, Christian Stoller = wrote: > Hi internals, > > what do you think about improving the modification functionality of th= e = > DateTime class. I always get a cold shiver, when I write something lik= e = > this: > $date =3D new DateTime() > $date->modify(=E2=80=98+15 day=E2=80=99); > > In my opinion it would be nicer if one could write: > $date->modify(15, DateTime::INTERVAL_DAY); // for adding 15 days > $date->modify(-15, DateTime::INTERVAL_DAY); // for subtracting 15 days= > > Even better would be to have methods like addDays(), addMonths(), etc.= > > This would make it cleaner and more readable. You do not have to do = > something like this: > > $date =3D new DateTime(); > $date->modify(getDaysToAddMethod() . " day"); // I am not sure if a '+= ' = > sign is needed if the value is positive > > And it is fully backward compatible. > > Best regards > Christian > Hi, I think we shouldn't improve this functionality because modifying date = object in the first place is bad idea. Think about it as monatomic objec= t, = like integer, you can't create new integer object of 42 and then just = change its value - it will be another object. As a workaround you could create your own date class, extend it from = \DateTime and add what you want.