Skip to content

[Form] BirthdayType and dates before 1583 #31057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
althaus opened this issue Apr 10, 2019 · 13 comments
Open

[Form] BirthdayType and dates before 1583 #31057

althaus opened this issue Apr 10, 2019 · 13 comments

Comments

@althaus
Copy link
Contributor

althaus commented Apr 10, 2019

Symfony version(s) affected: 4.2.x

Description

We encountered an issue with the BirthdayType and dates before the Gregorian calendar changes took place. I don't know the reason, but it maybe just an issue with php-intl. When using January, 1st 1582 as a birthday the view format (using German format in the screenshot) goes nuts:

birthday

PHP got it correctly but the view format gets off the 11 added days: https://en.wikipedia.org/wiki/Gregorian_calendar#Gregorian_reform

How to reproduce

Create a form with a BirthdayType and set new \DateTime('1582-01-01) as the data.

Possible Solution

No clue. As this seems to be handled by the IntlFormatter that is broken or unable to handle this? I' just confused.

@althaus althaus changed the title [ [Form] BirthdayType and dates before 1583 Apr 10, 2019
@apfelbox
Copy link
Contributor

Yep, seems to be the same issue.

@xabbuh
Copy link
Member

xabbuh commented May 3, 2019

see #31374 for an attempt to fix this

@javiereguiluz
Copy link
Member

Closing as fixed by #31374.

@xabbuh
Copy link
Member

xabbuh commented Sep 19, 2020

That PR wasn't merged. Thus let's reopen here.

@xabbuh xabbuh reopened this Sep 19, 2020
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@althaus
Copy link
Contributor Author

althaus commented Mar 23, 2021

Still broken I guess.

@carsonbot carsonbot removed the Stalled label Mar 23, 2021
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

@apfelbox
Copy link
Contributor

apfelbox commented Oct 8, 2021

As @xabbuh already indicated with the label: I still think properly handling all dates in these types is important.

@fabpot
Copy link
Member

fabpot commented Oct 9, 2021

Who wants to investigate this issue and maybe work on a fix?

@connorhu
Copy link
Contributor

I have started to investigate this problem and so far it seems to work correctly that the date before 1582-10-15 is not a valid date according to the Gregorian calendar. If someone enters a date that is on or before 1582-10-14, then there the date entered is intended to be a Julian calendar string date (<1582-10-14 is an invalid date in Gregorian cal.). This date needs to be converted to a Gregorian date, since \DateTime handles well only the Gregorian calendar.

When the time zone enters the picture php starts to do very strange things. Further research is needed to find out how this part of the PHP works.

@connorhu
Copy link
Contributor

If I don't allow pre-Gregorian dates to be formatted by IntlDateFormatter in the DateTimeToLocalizedStringTransformer::transform method, then PR #31374 starts working correctly even if the timezone is not UTC. The main reason for this, I think, is that IntlCalendar cannot be Gregorian, so I have to define my own. I can't yet see if IntlCalendar can describe the Julian calendar behaviour, or if in this case I have to skip the intl formatter altogether.

        if ($timestamp >= -12219292800) {
            $value = $this->getIntlDateFormatter()->format($timestamp);
        } else {
            $value = $dateTime->format('Y-m-d');
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants