Giter Site home page Giter Site logo

Comments (4)

hormus avatar hormus commented on May 15, 2024 2

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 (ex .1969-12-31 23:59:59.100000 format('U') -1 and format('u') 100000) , 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.

<?php

error_reporting(PHP_INT_MAX);
//PHP >= 7.1.0
ini_set('precision', -1);
ini_set('serialize_precision', -1);
$string = microtime(); //"msec sec"
//msec 10.0E-8 if last two digit is significant
$typefloat = microtime(TRUE);
$positive_int = PHP_INT_MAX;
$negative_int = -1 + -$positive_int;
$mymsec = '000010';
$mymsec = '';
$check = NULL;
if(is_string($mymsec)) {
$arr = preg_split('//', $mymsec); // support for empty string ''
if(is_array($arr)) {
$count = count($arr);
$stop1 = 0;
$stop2 = $count - 1;
$stop3 = $count - 2;
$y = 0;
if($count) {
foreach($arr as $key => $value) {
if($key != $stop1) {
$ordv = ord($value);
if($ordv < 58 && $ordv > 47) {
$y = $y + 1;
if(!isset($val)) {
if($ordv > 48) {
$arr2[] = chr($ordv);
$val = $key;
}
} else {
$arr2[] = chr($ordv);
}
if($stop3 == $y && empty($error)) {
$check = TRUE;
}
} else {
$error = 1;
}
} else {
if(0 == $key) {
$stop1 = $stop2;
} else {
$stop1 = $stop3;
}
}
if($key == $stop3) {
break;
}
}
}
}
}
var_dump($string, $typefloat, (float) ($negative_int . '.100500'));
if($check) {
if(empty($arr2)) {
$arr2 = array('0', '0', '0', '0', '0', '0');
$val = FALSE;
}
var_dump(implode('', $arr2), 'first not zero key ' . $val);
}
elseif(!isset($error) && isset($count)) {
var_dump('000000', 'first zero'); //$mymsec is empty string ''
}

(float) ($negative_int . '.100500') as greater than 17 digits the float loses precision.
length 6 for usec of DateTime.

Note* I call it number sequence because with class DateTime and format('U) it can return a float in an OS limited to 32bit, but Unix Time is an optional signed integer for DateTime::__construct('now', $timezone) or string into float/int for 32bit DateTime::format('U'). On the latter issue, I guessed please @derickr your input is appreciated, thank you.
32bit PHP_INT_MAX 2147483647 support DateTime 64bit, example '@100000000000' https://bugs.php.net/bug.php?id=52062

from php-src.

damianwadley avatar damianwadley commented on May 15, 2024

For the explanation: fractional timestamps are currently not supported when parsing, which means PHP handles inputs like @-1.4 as an absolute "@-1" (1970 minus 1s) followed by a relative ".4" (plus 0.4s).

from php-src.

mvorisek avatar mvorisek commented on May 15, 2024

For the explanation: fractional timestamps are currently not supported when parsing, which means PHP handles inputs like @-1.4 as an absolute "@-1" (1970 minus 1s) followed by a relative ".4" (plus 0.4s).

this is how it is parsed currently probably, however if unix timestamp is negative, the fractional part must be decremented as if the whole TS was a standard floating point number

https://3v4l.org/rKOAb shows the fractional part cannot be even used alone (eg. parsed with @ts token and the parsing must be fixed)

from php-src.

iluuu1994 avatar iluuu1994 commented on May 15, 2024

I think it's fair to say that this a feature request as the docs do state that only whole numbers are supported.

from php-src.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.