Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86110 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86148 invoked from network); 4 May 2015 19:52:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 May 2015 19:52:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=dlundgren@syberisle.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dlundgren@syberisle.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain syberisle.net designates 96.126.116.40 as permitted sender) X-PHP-List-Original-Sender: dlundgren@syberisle.net X-Host-Fingerprint: 96.126.116.40 li341-40.members.linode.com Received: from [96.126.116.40] ([96.126.116.40:53887] helo=li341-40.members.linode.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/60-16879-3FDC7455 for ; Mon, 04 May 2015 15:52:25 -0400 Received: from localhost (admin.local [127.0.0.1]) by li341-40.members.linode.com (Postfix) with ESMTP id 7B4E9251EC for ; Mon, 4 May 2015 15:52:16 -0400 (EDT) Received: from li341-40.members.linode.com ([127.0.0.1]) by localhost (li341-40.members.linode.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rYfW8jGuHTIv for ; Mon, 4 May 2015 15:52:15 -0400 (EDT) Received: from Davids-MacBook-Pro-3.local (unknown [66.195.151.70]) (Authenticated sender: dlundgren@syberisle.net) by li341-40.members.linode.com (Postfix) with ESMTPSA id D196A251E8 for ; Mon, 4 May 2015 15:52:15 -0400 (EDT) Message-ID: <5547CD9C.9040404@syberisle.net> Date: Mon, 04 May 2015 14:50:52 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <55479144.7060704@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Adding weekdays to DateTime resets the time From: dlundgren@syberisle.net (David Lundgren) There is actually already a bug for about this: https://bugs.php.net/bug.php?id=54909 I ran into this several months ago when I upgraded a project from 5.3.2 to 5.5 and found that in 5.3.6 the behavior had changed. I ended up working around it in my code. It was definitely annoying but had we upgraded PHP versions sooner I wouldn't have had any issue with this in the time crunch I had. Our unit tests around that code, while complex, became that much better to actually account for the finer details of date/time. - Dave On 5/4/15 12:49 PM, Stelian Mocanita wrote: > I think the best approach would be to open a bug under https://bugs.php.net/ > since this does > not look like intended behavior. > > Regards, > Stelian > > On Mon, May 4, 2015 at 5:33 PM, Markus Fasselt > wrote: > >> Hi, >> >> when I modify a DateTime object and add or subtract weekdays, it happens >> that the current time is reset to 00:00:00. >> >> This effect does not occur when I add days. I also experienced the same >> behavior with strototime. >> >>> >> >>> $a = new DateTime(strtotime('2015-05-04 17:22')); >>> var_dump((string) $a->format('Y-m-d H:i:s')); // 2015-05-04 17:22:00 >>> $a->modify('+1 day'); >>> var_dump((string) $a->format('Y-m-d H:i:s')); // 2015-05-05 17:22:00 >>> $a->modify('+1 weekday'); >>> var_dump((string) $a->format('Y-m-d H:i:s')); 2015-05-06 00:00:00 >>> >>> var_dump(date('Y-m-d H:i:s', strtotime('+1 weekday'))); // 2015-05-05 >> 00:00:00 >> >> http://3v4l.org/554H4 >> >> There seems to be slighly different behavior between the different PHP >> versions. strotime always had this behavior. DateTime::modify() worked >> correct until PHP 5.3.5. >> >> I don't know if this behavior was changed on purpose (I didn't find >> something on it). If so, why? Otherwise I would suggest to fix this, as >> it is really confusing. >> >> Regards, >> Markus >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >