Skip to content

Commit 99950bd

Browse files
committed
Merged pull request #14375
2 parents 471aa11 + 92d18b2 commit 99950bd

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

ext/date/php_date.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,7 @@ PHPAPI bool php_date_initialize_from_ts_double(php_date_obj *dateobj, double ts)
25382538
}
25392539

25402540
sec = (zend_long)sec_dval;
2541-
usec = (int)(fmod(ts, 1) * 1000000);
2541+
usec = (int) round(fmod(ts, 1) * 1000000);
25422542

25432543
if (UNEXPECTED(usec < 0)) {
25442544
if (UNEXPECTED(sec == TIMELIB_LONG_MIN)) {

ext/date/tests/createFromTimestamp.phpt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ $timestamps = array(
2222
PHP_INT_MIN - 1025.0,
2323
NAN,
2424
+INF,
25-
-INF
25+
-INF,
26+
1599828571.235628,
27+
-1599828571.235628,
2628
);
2729

2830
foreach ($timestamps as $ts) {
@@ -211,6 +213,38 @@ DateTime::createFromTimestamp(INF): DateRangeError: DateTime::createFromTimestam
211213
DateTimeImmutable::createFromTimestamp(INF): DateRangeError: DateTimeImmutable::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between %i and %i.999999, INF given
212214
DateTime::createFromTimestamp(-INF): DateRangeError: DateTime::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between %i and %i.999999, -INF given
213215
DateTimeImmutable::createFromTimestamp(-INF): DateRangeError: DateTimeImmutable::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between %i and %i.999999, -INF given
216+
DateTime::createFromTimestamp(1599828571.235628): object(DateTime)#%d (3) {
217+
["date"]=>
218+
string(26) "2020-09-11 12:49:31.235628"
219+
["timezone_type"]=>
220+
int(1)
221+
["timezone"]=>
222+
string(6) "+00:00"
223+
}
224+
DateTimeImmutable::createFromTimestamp(1599828571.235628): object(DateTimeImmutable)#%d (3) {
225+
["date"]=>
226+
string(26) "2020-09-11 12:49:31.235628"
227+
["timezone_type"]=>
228+
int(1)
229+
["timezone"]=>
230+
string(6) "+00:00"
231+
}
232+
DateTime::createFromTimestamp(-1599828571.235628): object(DateTime)#%d (3) {
233+
["date"]=>
234+
string(26) "1919-04-22 11:10:28.764372"
235+
["timezone_type"]=>
236+
int(1)
237+
["timezone"]=>
238+
string(6) "+00:00"
239+
}
240+
DateTimeImmutable::createFromTimestamp(-1599828571.235628): object(DateTimeImmutable)#%d (3) {
241+
["date"]=>
242+
string(26) "1919-04-22 11:10:28.764372"
243+
["timezone_type"]=>
244+
int(1)
245+
["timezone"]=>
246+
string(6) "+00:00"
247+
}
214248
MyDateTime::createFromTimestamp(0): object(MyDateTime)#%d (3) {
215249
["date"]=>
216250
string(26) "1970-01-01 00:00:00.000000"

0 commit comments

Comments
 (0)