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:

        [PHP: 7.1.0-dev  ] derick@whisky:~ $ cat /tmp/midnight.php
        <?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?

> 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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to