IntlCalendar/intlDateFormatere calculate wrongly the calendar-transformation gregorian->islamic ->gregorian and others
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
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
$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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied IntlDateFormatter example across the PHP versions listed and compare the observed calendar conversions with the relevant PHP documentation. Determine whether the behavior is a documentation problem or an implementation bug; done means recording that conclusion and updating the appropriate documentation if the documented behavior is incorrect.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation, internationalization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100