Comments (4)
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.
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.
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.
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)
- [spam]
- getAttribute('xmlns') returns NULL when using the new DOM API HOT 4
- Backward incompatibility on date function 8.1+ HOT 6
- Using NumberFormatter::DECIMAL_ALWAYS_SHOWN adds the currency symbol to format() method output HOT 1
- Improve the error message of duplicated class declaration
- sqlite PDO::quote silently corrupts strings with null bytes HOT 11
- Add "abstract constant" support
- PDO PostreSQL - parser is broken for `'...\'` HOT 15
- Issue with ob handler context and execution in PHP HOT 5
- Anonymous classes with dynamic parent class HOT 7
- Build failed at mbstring_arginfo.h on Windows(Visual C++) with --enable-mbregex
- Incorrect validation of #[\Attribute]’s first parameter HOT 2
- better error message for when upload_max_filesize is exceeded HOT 1
- DateInterval cannot parse decimal fraction in ISO duration string
- Fuzzer readme still mentions obsolete --enable-json flag
- Maintain a docker tag for nightly master build HOT 7
- Heap Buffer Overflow in sqlite extension HOT 2
- Storing DOMElement consume 4 times more memory in PHP 8.1 than in PHP 8.0 HOT 3
- PHP checks the filesystem for file existing even if available in opcache and all opcache validations are disabled HOT 21
- binary diff generated for arginfo.h HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-src.