[php-src] Issue #7758: Datetime created from negative float timestamp is not monotonic (fraction part is added instead of substracted)
| From: | hormus | Date: | Sun, 24 Apr 2022 20:45:38 +0000 |
| Subject: | [php-src] Issue #7758: Datetime created from negative float timestamp is not monotonic (fraction part is added instead of substracted) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241219@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7758
Comment Author: hormus
Confusing is a documentation problem, Unix time is a number sequence * for negative values the
sign exists otherwise for positive values it is omitted. the DateTime class supports the
theoretical limit from 2 ^ 64-1 to -2 ^ 64 regardless of your operating system support, old php
versions had a block (internal functions limited to 32bit) even on a 64bit system. From php 7.4.0
the support for milliseconds has been extended through the v format, while from php 8.0.0 through
the unix time format preceded by the character @ seconds with decimal point and microseconds. Every
1000 microseconds is a millisecond and since the constructor does not accept arbitrary fractions it
is with the limit of 6 digits from php 5.0.0 in strtotime but visible with DateTime :: format
('u') (created by php 5.2.2) since strtotime returns a signed integer, otherwise called
Unix Time. Since there cannot exist format ('U') and format ('u') with different
results, ie the unix time operator '@ -1 .100000' the desired behavior is to subtract 1
second and set 100000 otherwise it creates confusion. Also a float -0.0 or -0.1 converted to integer
is 0 seconds while 000000 microseconds or 100000. Without considering that the arithmetic in float
loses precision, well explain that it is recommended to insert a string in the constructor rather
than the value of type int or float, since Via user code often a simple conversion of 6 digits after
the decimal point can be converted into integer with the exception if preceded by 0 and carry out
the relative subtractions or additions. Ie there is no subtracting microseconds with '@
-1..100000' is a positive value by definition with the exception of seconds. Other languages
adopt Unix time as a float but this is not the case with php as it is integer. Please correct
me if I'm wrong, thanks..