php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76938 IntlDateFormatter::formatObject is formatting date incorrectly in some cases
Submitted: 2018-09-26 14:09 UTC Modified: 2018-09-26 14:27 UTC
From: joyce at ennexa dot com Assigned: cmb (profile)
Status: Not a bug Package: intl (PECL)
PHP Version: 7.1.22 OS: Mac OSX 10.13
Private report: No CVE-ID: None
 [2018-09-26 14:09 UTC] joyce at ennexa dot com
Description:
------------
---
From manual page: http://www.php.net/intldateformatter.formatobject
---
IntlDateFormatter::formatObject on a DateTime object is generating an incorrect output. For 1987-12-29, it is giving the output year as 1988.

I was able to replicate the issue on multiple PHP versions

7.0.32, 7.1.22 and 7.2.7  

For demo , run the test script at http://www.writephponline.com/

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

echo PHP_VERSION . PHP_EOL . PHP_EOL;
$date = new DateTime('1987-12-29 19:14:00', new DateTimezone('Asia/Kolkata'));
print_r($date);
echo PHP_EOL . PHP_EOL;

$formatted = IntlDateFormatter::formatObject($date, 'MMMM d, YYYY', 'en');
echo $formatted;

Expected result:
----------------
7.1.22

DateTime Object
(
    [date] => 1987-12-29 19:14:00.000000
    [timezone_type] => 3
    [timezone] => Asia/Kolkata
)


December 29, 1987

Actual result:
--------------
7.1.22

DateTime Object
(
    [date] => 1987-12-29 19:14:00.000000
    [timezone_type] => 3
    [timezone] => Asia/Kolkata
)


December 29, 1988      

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-26 14:27 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-09-26 14:27 UTC] cmb@php.net
Y is the year of "Week of Year"[1]; use y instead.

[1] <http://userguide.icu-project.org/formatparse/datetime>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC