2.x - ChronosInterval doesn't support fractional/microseconds
othercorey opened this issue · comments
PHP 7.1 added some support for fractional seconds in DateInterval
.
https://www.php.net/manual/en/class.dateinterval.php
They added a $f
property which stores microseconds as a decimal fraction. So if the interval is 2.5 seconds then $s
is 2
and $f
is 0.5
. This is populated when an interval is created from diffing two DateTime instances.
However, DateInterval's constructor does not support fractional seconds in the spec string.
There are several ways to add support for getting microseconds:
- Simply expose $f via 'microseconds' property and leave it as a fractional second
- Expose $f via 'microseconds' but convert it into an integer number of microseconds.
- Add $f fractional seconds to $s when returning 'seconds'
Adding support for setting microseconds is probably limited:
- Allow setting $f via 'microseconds' as a fractional second
- Allow setting $f via 'microseconds' as an integer number of microseconds
- Allow setting $f via 'seconds' containing seconds and fractional second together
Exposing the f
property as a fractional using and microseconds
as an integer seems reasonable to me. It lets us be compatible with PHP's DateInterval and also improve the interface with our extensions.