com php-src: Fixed #74298 - IntlDateFormatter->format() doesn't return microseconds/fractions: NEWS ext/intl/common/common_date.cp p
ext/intl/tests/bug74298.phpt
| From: | Nikita Popov | Date: | Sun, 09 Apr 2017 10:56:21 +0000 |
| Subject: | com php-src: Fixed #74298 - IntlDateFormatter->format() doesn't return microseconds/fractions: NEWS ext/intl/common/common_date.cp p ext/intl/tests/bug74298.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-97492@lists.php.net to get a copy of this message | ||
Commit: 1ce355abb648dc6814ddd00876085617a946396f
Author: andrewnester <andrew.nester.dev@gmail.com> Fri, 24 Mar 2017 19:23:15 +0300
Committer: Nikita Popov <nikita.ppv@gmail.com> Sun, 9 Apr 2017 12:56:21 +0200
Parents: a813cebff082398f0bbdb0d95ece10ea14b9d946
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1ce355abb648dc6814ddd00876085617a946396f
Log:
Fixed #74298 - IntlDateFormatter->format() doesn't return microseconds/fractions
Bugs:
https://bugs.php.net/74298
Changed paths:
M NEWS
M ext/intl/common/common_date.cpp
A ext/intl/tests/bug74298.phpt
Diff:
diff --git a/NEWS b/NEWS
index ab04592..2fbfa00 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,8 @@ PHP NEWS
- Intl:
. Fixed bug #65683 (Intl does not support DateTimeImmutable). (Ben Scholzen)
+ . Fixed bug #74298 (IntlDateFormatter->format() doesn't return
+ microseconds/fractions). (Andrew Nester)
- OpenSSL:
. Fixed bug #74341 (openssl_x509_parse fails to parse ASN.1 UTCTime without
diff --git a/ext/intl/common/common_date.cpp b/ext/intl/common/common_date.cpp
index 98c6393..26c198b 100644
--- a/ext/intl/common/common_date.cpp
+++ b/ext/intl/common/common_date.cpp
@@ -125,6 +125,8 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz,
}
if (millis) {
+ php_date_obj *datetime;
+
ZVAL_STRING(&zfuncname, "getTimestamp");
if (call_user_function(NULL, z, &zfuncname, &retval, 0, NULL)
!= SUCCESS || Z_TYPE(retval) != IS_LONG) {
@@ -137,7 +139,8 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz,
return FAILURE;
}
- *millis = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval);
+ datetime = Z_PHPDATE_P(z);
+ *millis = U_MILLIS_PER_SECOND * ((double)Z_LVAL(retval) + datetime->time->f);
zval_ptr_dtor(&zfuncname);
}
diff --git a/ext/intl/tests/bug74298.phpt b/ext/intl/tests/bug74298.phpt
new file mode 100644
index 0000000..0600a46
--- /dev/null
+++ b/ext/intl/tests/bug74298.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #74298 (IntlDateFormatter->format() doesn't return microseconds/fractions)
+--SKIPIF--
+<?php if (!extension_loaded('intl')) print 'skip'; ?>
+--FILE--
+<?php
+var_dump((new \DateTime('2017-01-01
01:02:03.123456'))->format('Y-m-d\TH:i:s.u'));
+
+var_dump((new \IntlDateFormatter(
+ 'en-US',
+ \IntlDateFormatter::FULL,
+ \IntlDateFormatter::FULL,
+ 'UTC',
+ \IntlDateFormatter::GREGORIAN,
+ 'yyyy-MM-dd HH:mm:ss.SSSSSS'
+))->format(new \DateTime('2017-01-01 01:02:03.123456')));
+
+var_dump(datefmt_create(
+ 'en-US',
+ \IntlDateFormatter::FULL,
+ \IntlDateFormatter::FULL,
+ 'UTC',
+ \IntlDateFormatter::GREGORIAN,
+ 'yyyy-MM-dd HH:mm:ss.SSSSSS'
+)->format(new \DateTime('2017-01-01 01:02:03.123456')));
+?>
+--EXPECTF--
+string(26) "2017-01-01T01:02:03.123456"
+string(26) "2017-01-01 01:02:03.123000"
+string(26) "2017-01-01 01:02:03.123000"