php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65184 strftime() returns insufficient-length string under multibyte locales
Submitted: 2013-07-02 15:50 UTC Modified: 2013-07-03 20:55 UTC
From: k-yamashita at ver2 dot jp Assigned: ab (profile)
Status: Closed Package: Date/time related
PHP Version: 5.5.0 OS: Windows
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: k-yamashita at ver2 dot jp
New email:
PHP Version: OS:

 

 [2013-07-02 15:50 UTC] k-yamashita at ver2 dot jp
Description:
------------
VC11's strftime() returns number of wide characters rather than bytes but PHP seems to rely on it to determine byte length.

http://connect.microsoft.com/VisualStudio/feedback/details/766205/vs2012-strftime-has-incorrect-return-value-in-vc-11-with-multibyte-codepages


Test script:
---------------
<?php
setlocale(LC_ALL, 'Japanese_Japan.932');
echo strftime('%A');


Expected result:
----------------
>php a.php | od -t x1
0000000 90 85 97 6a 93 fa
0000006

Above is Shift JIS encoded Japanese word for "Wednesday". Other week days are all 6 bytes long too.


Actual result:
--------------
>php a.php | od -t x1
0000000 90 85 97
0000003


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-03 07:32 UTC] ab@php.net
-Assigned To: +Assigned To: ab
 [2013-07-03 09:25 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5324416b6514b6de53e7de269bc18b5807701051
Log: Fixed bug #65184 strftime() returns insufficient-length
 [2013-07-03 09:25 UTC] ab@php.net
-Status: Assigned +Status: Closed
 [2013-07-03 09:30 UTC] ab@php.net
@k-yamashita please test the next snapshot.

Thanks.
 [2013-07-03 19:17 UTC] k-yamashita at ver2 dot jp
It works fine. Thanks a lot!

Well, checking byte values will fail if unit test is performed on other than Wednesday. I suggest just checking the length.

--FILE--
<?php
	setlocale(LC_ALL, 'Japanese_Japan.932');
	echo strlen(strftime('%A')) . "\n";
?>
===DONE===
--EXPECT--
6
===DONE===
 [2013-07-03 20:55 UTC] ab@php.net
Thanks for pointing to that. So lets do both, just pushed a fix passing an 
explicit timestamp.
 [2013-11-17 09:30 UTC] laruence@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5324416b6514b6de53e7de269bc18b5807701051
Log: Fixed bug #65184 strftime() returns insufficient-length
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Apr 07 17:01:29 2025 UTC