php.net |  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
Votes:9
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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mathieuk at gmail dot com
New email:
PHP Version: OS:

 

 [2008-08-15 06:13 UTC] mathieuk at gmail dot com
Description:
------------
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:
---------------
<?php

$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

Patches

Pull Requests

History

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] stas@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2010-09-01 20:08 UTC] stas@php.net
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] cmb@php.net
-Status: Assigned +Status: Closed -Package: *General Issues +Package: intl
 [2015-08-18 17:32 UTC] cmb@php.net
Indeed, that is already supported as of PHP 5.5.0, see
<https://3v4l.org/gFvPo>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 18:01:26 2024 UTC