php / php/doc-en

IntlCalendar/intlDateFormatere calculate wrongly the calendar-transformation gregorian->islamic ->gregorian and others

Open
#2,246 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: intl Status: Needs Triage
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.