Req #45829 [Com]: [intl] Allow MessageFormatter / IntlDateFormatter to accept DateTime objects?
| From: | gmblar+php at gmail dot com | Date: | Sat, 11 Jan 2014 10:45:24 +0000 |
| Subject: | Req #45829 [Com]: [intl] Allow MessageFormatter / IntlDateFormatter to accept DateTime objects? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183713@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=45829&edit=1
ID: 45829
Comment by: gmblar+php at gmail dot com
Reported by: mathieuk at gmail dot com
Summary: [intl] Allow MessageFormatter / IntlDateFormatter to
accept DateTime objects?
Status: Assigned
Type: Feature/Change Request
Package: *General Issues
Operating System: Mac OSX 10.5
PHP Version: 5.3.0alpha1
Assigned To: stas
Block user comment: N
Private report: N
New Comment:
Democode works as expected in PHP 5.5.7 and INTL 1.1.0
Previous Comments:
------------------------------------------------------------------------
[2010-09-01 20:08:26] stas@php.net
Yes, this is on the TODO list (contributions welcome! :)
------------------------------------------------------------------------
[2008-08-16 16:09:15] mathieuk at gmail dot com
Additionally, MessageFormatter::parse() might return a DateTime object
instead of a UNIX timestamp.
------------------------------------------------------------------------
[2008-08-15 06:13:57] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=45829&edit=1