[php-src] Issue #10411: IntlCalendar/intlDateFormatere calculate wrongly the calendar-transformation gregorian->islamic ->gregorian and others
| From: | porthd | Date: | Sun, 22 Jan 2023 13:58:44 +0000 |
| Subject: | [php-src] Issue #10411: IntlCalendar/intlDateFormatere calculate wrongly the calendar-transformation gregorian->islamic ->gregorian and others | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243532@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10411
Author: porthd
### Description
I tested the following code on a phpsandbox (https://onlinephp.io/) The code will transform a
gregorian Datetime into a islamic
datetime. After that the islamice
datetime will be transformed into a gregorian datetime. I would expect the
original datetime. I got something else.
I used the code from the link https://stackoverflow.com/questions/24042819/converting-non-gregorian-dates-using-intldateformatter
for this example.
A similar problem happens with the calendar chinese od buddhist. I have
not tested the other calendars. Even if you use the calendar gregorian, I will get
wrong results.
Perhaps I read the documentation in the wrong way.
The following code:
```php[
<?php
$calendar = 'islamic';
$fmt = new IntlDateFormatter(
'de_DE@calendar=gregorian',
IntlDateFormatter::SHORT, //date format
IntlDateFormatter::SHORT, //time format
'Europe/Berlin',
IntlDateFormatter::TRADITIONAL
);
// $fmt->setPattern('MM-dd-YYYY HH:mm:ss');
$time = $fmt->parse('09/13/2022 13:46');
echo('tstamp: '.$time."\n");
$formatter = IntlDateFormatter::create("de_DE@calendar=".$calendar,
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Europe/Berlin',
IntlDateFormatter::TRADITIONAL);
// $formatter->setPattern('MM-dd-YYYY HH:mm:ss');
echo ($help = $formatter->format($time)."\n");
$list = explode(' ',$help);
$fmt = new IntlDateFormatter(
'de_DE@calendar='.$calendar,
IntlDateFormatter::SHORT, //date format
IntlDateFormatter::SHORT, //time format
'Europe/Berlin',
IntlDateFormatter::TRADITIONAL
);
// $fmt->setPattern('MM-dd-YYYY HH:mm:ss');
$time = $fmt->parse($help);
echo('tstamp: '.$time."\n");
$formatter = IntlDateFormatter::create("de_DE@calendar=gregorian",
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Europe/Berlin',
IntlDateFormatter::GREGORIAN
);
// $formatter->setPattern('MM-dd-YYYY HH:mm:ss');
echo ($help = $formatter->format($time)."\n".'This should be 09/13/22
13:46');
```
Resulted in this output:
```
tstamp: 1673268360
17.6.1444 AH 13:46
tstamp: 1673268360
09.01.23 13:46
This should be 09/13/22 13:46
```
But I expected this output instead:
```
17.6.1444 AH 13:46
tstamp: 1673268360
09/13/22 13:46
This should be 09/13/22 13:46
```
### PHP Version
php 7.4.21; php 8.0.27, php 8.1.14, php 8.2.1
### Operating System
_No response_