|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45829 [intl] Allow MessageFormatter / IntlDateFormatter to accept DateTime objects?
Submitted: 2008-08-15 06:13 UTC Modified: 2015-08-18 17:32 UTC
Avg. Score:3.6 ± 0.8
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:2 (33.3%)
From: mathieuk at gmail dot com Assigned: stas (profile)
Status: Closed Package: intl (PECL)
PHP Version: 5.3.0alpha1 OS: Mac OSX 10.5
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: mathieuk at gmail dot com
New email:
PHP Version: OS:


 [2008-08-15 06:13 UTC] mathieuk at gmail dot com
Feature request for the new intl extension.

Both the MessageFormatter and the IntlDateFormatter accept values for 
dates. The IntlDateFormatter accepts both Unix timestamps and the value 
for localtime(). I'm assuming it's the same for the MessageFormatter.

Since PHP 5.2 we have the DateTime object through the standard date 
extension. While it's easy to get the unix timestamp from a DateTime 
object through DateTime::getTimestamp() introduce in 5.3, this is an 
extra statement which just adds clutter.

Could these two formatters be made to also accept DateTime objects ?

Reproduce code:

$date = new DateTime("1 year ago");

$msgfmt = MessageFormatter::create('nl_NL', 'Today one year ago is {0,date}');

echo $msgfmt->format(array($date));


Expected result:
Output: Today one year ago is 15 aug 2007

Actual result:
Output: Today one year ago is 1 jan 1970


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-16 16:09 UTC] mathieuk at gmail dot com
Additionally, MessageFormatter::parse() might return a DateTime object 
instead of a UNIX timestamp.
 [2010-09-01 20:08 UTC]
-Package: Feature/Change Request +Package: *General Issues
 [2010-09-01 20:08 UTC]
Yes, this is on the TODO list (contributions welcome! :)
 [2014-01-11 10:45 UTC] gmblar+php at gmail dot com
Democode works as expected in PHP 5.5.7 and INTL 1.1.0
 [2015-08-18 17:32 UTC]
-Status: Assigned +Status: Closed -Package: *General Issues +Package: intl
 [2015-08-18 17:32 UTC]
Indeed, that is already supported as of PHP 5.5.0, see
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 09:01:28 2024 UTC