mirror of
https://github.com/php/php-src.git
synced 2025-01-22 11:44:09 +08:00
Fixed Bug #63435 Datetime::format('u') sometimes wrong by 1 microsecond
When storing '015700' microseconds in a Datetime object, Datetime::format('u') returns '015699' Already known per bug45554 reproducer (also fixed).
This commit is contained in:
parent
ff6c9e2726
commit
c2554b4bb4
@ -1095,7 +1095,7 @@ static char *date_format(char *format, int format_len, timelib_time *t, int loca
|
||||
case 'H': length = slprintf(buffer, 32, "%02d", (int) t->h); break;
|
||||
case 'i': length = slprintf(buffer, 32, "%02d", (int) t->i); break;
|
||||
case 's': length = slprintf(buffer, 32, "%02d", (int) t->s); break;
|
||||
case 'u': length = slprintf(buffer, 32, "%06d", (int) floor(t->f * 1000000)); break;
|
||||
case 'u': length = slprintf(buffer, 32, "%06d", (int) floor(t->f * 1000000 + 0.5)); break;
|
||||
|
||||
/* timezone */
|
||||
case 'I': length = slprintf(buffer, 32, "%d", localtime ? offset->is_dst : 0); break;
|
||||
|
@ -9,12 +9,12 @@ $d = date_create_from_format($format, "03-15-2005 12:22:29.000000 PST");
|
||||
echo $d->format($format), "\n";
|
||||
|
||||
$d = date_create_from_format($format, "03-15-2005 12:22:29.001001 PST");
|
||||
echo $d->format($format), " (precision isn't enough to show the 1 here)\n";
|
||||
echo $d->format($format), "\n";
|
||||
|
||||
$d = date_create_from_format($format, "03-15-2005 12:22:29.0010 PST");
|
||||
echo $d->format($format), "\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
03-15-2005 12:22:29.000000 PST
|
||||
03-15-2005 12:22:29.001000 PST (precision isn't enough to show the 1 here)
|
||||
03-15-2005 12:22:29.001001 PST
|
||||
03-15-2005 12:22:29.001000 PST
|
||||
|
16
ext/date/tests/bug63435.phpt
Normal file
16
ext/date/tests/bug63435.phpt
Normal file
@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Bug #63435 Datetime::format('u') sometimes wrong by 1 microsecond
|
||||
--INI--
|
||||
date.timezone=UTC
|
||||
--FILE--
|
||||
<?php
|
||||
for ($i=1 ; $i<999 ; $i++) {
|
||||
$datetime = Datetime::createFromFormat("u", sprintf("%06ld", $i));
|
||||
$res = $datetime->format("u");
|
||||
if ($res != $i) {
|
||||
echo "$i != $res\n";
|
||||
}
|
||||
}
|
||||
echo "Done";
|
||||
--EXPECT--
|
||||
Done
|
Loading…
Reference in New Issue
Block a user