Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96777 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74599 invoked from network); 8 Nov 2016 19:41:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Nov 2016 19:41:23 -0000 X-Host-Fingerprint: 77.165.170.254 ip4da5aafe.direct-adsl.nl Received: from [77.165.170.254] ([77.165.170.254:7656] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/D5-23587-04622285 for ; Tue, 08 Nov 2016 14:23:44 -0500 Message-ID: <5D.D5.23587.04622285@pb1.pair.com> To: internals@lists.php.net References: <46.92.05967.9AB91285@pb1.pair.com> Date: Tue, 8 Nov 2016 20:23:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 77.165.170.254 Subject: Re: [PHP-DEV] DateTime microseconds discussion From: arjen@parse.nl (Arjen Schol) On 11/08/2016 01:46 PM, Derick Rethans wrote: > On Tue, 8 Nov 2016, Arjen Schol wrote: > >> Hi, >> >> Support for microseconds was added late in the 7.1 RC cycle, however is has >> some issues: > > Some *additional* support for microseconds was added in the PHP 7.1 > cycle, mostly to support bug fixes that have been around for a long > time. > >> >> 1. There is no easy way to set microseconds to 0, you have to call setTime see >> https://3v4l.org/YUhFF A setMicroseconds method would be handy and/or support >> to relative strings to set microseconds to 0 (just like midnight does for >> H:i:s). Or am I missing something? > > - You can't set just the seconds or minute portion alone either, > through setTime(). Microseconds are just an extension of the time > portion. > - Using "midnight" also sets the microseconds to 0: new DateTime('now midnight') obviously won't work... > > [PHP: 7.1.0-dev ] derick@whisky:~ $ cat /tmp/midnight.php > $a = new DateTimeImmutable(); > var_dump( $a ); > var_dump( $a->modify( 'midnight' ) ); > ?> > > [PHP: 7.1.0-dev ] derick@whisky:~ $ php -n /tmp/midnight.php > object(DateTimeImmutable)#1 (3) { > ["date"]=> > string(26) "2016-11-08 12:01:20.023680" > ["timezone_type"]=> > int(3) > ["timezone"]=> > string(3) "UTC" > } > object(DateTimeImmutable)#2 (3) { > ["date"]=> > string(26) "2016-11-08 00:00:00.000000" > ["timezone_type"]=> > int(3) > ["timezone"]=> > string(3) "UTC" > } > >> 2. Microsecond support is useful, by not by default I think. Why not >> introduce a 3rd parameter $with_microseconds/$set_microseconds which >> defaults to false? > > A 3rd parameter to which function? With 3rd argument I meant the constructor: public DateTime::__construct ([ string $time = "now" [, DateTimeZone $timezone = NULL, [ $initialize_microseconds = false ]]] ) When microseconds are NOT specified in $time, don't set them unless $initialize_microseconds is true. > >> Or A second class DateTimeWithMicroseconds? Maybe not so fancy naming, >> but it's very clear what will happen. > > But that would be a duplicate. The already existing DateTime and > DateTimeImmutable classes already support microseconds. Adding an extra > class for them, would just be confusing. > >> 3. The 4th parameter to setTime() should not cause BC breakage. > > Added additional new arguments with a default value, is not a BC break. > > cheers, > Derick >