php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69374 IntlDateFormatter formatObject returns wrong utf8 value
Submitted: 2015-04-04 08:40 UTC Modified: -
From: lenhatanh86 at gmail dot com Assigned:
Status: Closed Package: intl (PECL)
PHP Version: 5.6.7 OS: MacOS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lenhatanh86 at gmail dot com
New email:
PHP Version: OS:

 

 [2015-04-04 08:40 UTC] lenhatanh86 at gmail dot com
Description:
------------
IntlDateFormatter::formatObject returns wrong utf8 value when $format param is utf8 string pattern.

After check the "intl" source in github, I see maybe this bug comes from when processing input pattern in dateformat/dateformat_format_object.cpp file.

in line 139 : convert_to_string_ex(format); 
and
in line 192 : UnicodeString(Z_STRVAL_P(format), Z_STRLEN_P(format), 

Test script:
---------------
<?php

$millitimestamp = 1428133423941.0; // 14:43:43 April 04 2015

$fmt = new IntlDateFormatter('vi_VN',IntlDateFormatter::LONG, IntlDateFormatter::LONG, 'Asia/Ho_Chi_Minh');
$res3 = $fmt->format($millitimestamp / 1000);
$fmt->setPattern('\'tháng\' MM, y'); //yMM
$res1 = $fmt->format($millitimestamp / 1000);

$date = IntlCalendar::createInstance('Asia/Ho_Chi_Minh');
$date->setTime($millitimestamp);
$res2 = IntlDateFormatter::formatObject ($date, '\'tháng\' MM, y' /*yMM*/, 'vi_VN');
$res4 = IntlDateFormatter::formatObject ($date, [IntlDateFormatter::LONG, IntlDateFormatter::LONG], 'vi_VN');

echo $res1 . "\n" . $res2 . "\n";
echo ($res1 !== $res2) ? "Failed." : "Pass.";
echo "\n";
echo $res3 . "\n" . $res4 . "\n";
echo ($res3 !== $res4) ? "Failed." : "Pass.";
echo "\n";

Expected result:
----------------
tháng 04, 2015
tháng 04, 2015
Pass.
14:43:43 GMT+7 Ngày 04 tháng 04 năm 2015
14:43:43 GMT+7 Ngày 04 tháng 04 năm 2015
Pass.

Actual result:
--------------
tháng 04, 2015
tháng 04, 2015
Failed.
14:43:43 GMT+7 Ngày 04 tháng 04 năm 2015
14:43:43 GMT+7 Ngày 04 tháng 04 năm 2015
Pass.

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-02 20:45 UTC] ab@php.net
Automatic comment on behalf of lenhatanh86@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=527ddacd2084d5112ba849d55ed8532d133cbd97
Log: Fixed bug #69374 IntlDateFormatter formatObject returns wrong utf8 value
 [2016-06-02 20:45 UTC] ab@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:30 UTC] davey@php.net
Automatic comment on behalf of lenhatanh86@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=527ddacd2084d5112ba849d55ed8532d133cbd97
Log: Fixed bug #69374 IntlDateFormatter formatObject returns wrong utf8 value
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 08:01:28 2024 UTC