Skip to content
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

Dates before 1581 are not read correctly #9288

Open
manuth opened this issue Oct 15, 2019 · 5 comments
Open

Dates before 1581 are not read correctly #9288

manuth opened this issue Oct 15, 2019 · 5 comments

Comments

@manuth
Copy link
Contributor

manuth commented Oct 15, 2019

Affected Version

SilverStripe 4.4

phpunit/phpunit            5.7.27 The PHP Unit Testing framework.
silverstripe-themes/simple 3.2.0  The SilverStripe simple theme (default SilverStripe 3 theme)
silverstripe/recipe-cms    4.4.4  SilverStripe recipe for fully featured page and asset content editing
silverstripe/recipe-plugin 1.3.0  Helper plugin to install SilverStripe recipes

Description

Dates before 1581-01-01 are neither stored nor read correctly.

Steps to Reproduce

  1. Create a page type with a Date field in the $db array
  2. Create a SilverStripe\Forms\DateField using the getCMSFields() method
  3. In the CMS set the date to 1580-12-17
  4. Hit "Save"

Expected Behavior

The date value should equal 1580-12-17

Actual Behavior

The date displayed in the CMS is 1580-11-27

@manuth
Copy link
Contributor Author

manuth commented Oct 15, 2019

Also dates in the future (higher than 2040-04-01 like, for example 2040-04-02) are affected.

@robbieaverill
Copy link
Contributor

Possibly related: #8844

@phptek
Copy link

phptek commented Dec 1, 2019

Prob related to the introduction of the Julian Calendar in 1584?

@manuth
Copy link
Contributor Author

manuth commented Dec 2, 2019

Alright so I could verify that IntlDateFormatter is the source of the problem which formats the incorrect date. Sadly I couldn't find any issue about this sort of trouble - honestly I didn't even know what words to google as English isn't my main language.

Anyway I could also find out that IntlDateFormatter works correctly in combination with IntlCalendar!
So.... guys... it would be awesome if you could make DBDate using IntlCalendar instead of strtotime.

Example:

$year = 1580;
$month = 1;
$day = 20;

$calendar = IntlCalendar::createInstance(null, self::ISO_LOCALE);
$calendar->set(IntlCalendar::FIELD_YEAR, $year);
$calendar->set(IntlCalendar::FIELD_MONTH, $month - 1);
$calendar->set(IntlCalendar::FIELD_DAY_OF_MONTH, $day);
echo $formatter->format($calendar); // echos '1580-01-20'

@manuth
Copy link
Contributor Author

manuth commented Dec 2, 2019

@phptek I really don't know why the IntlDateFormatter wouldn't be able to do so.
Also that wouldn't explain why dates exactly before 1580-12-17 and exactly after 2040-04-01 aren't working.

However using IntlCalendar seems to solve this issue.

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

5 participants