为什么我的 IntlDateFormatter 格式化错误的日期?

Why is my IntlDateFormatter formatting the wrong day?

我正在尝试格式化过去的日期,但显然没有成功。

问题是,日期不仅有几个小时的偏差(这可能是由于时区不同),而是 5 天

这是我的示例代码:

<?php

$locale = "de";
$intlTimezone = \IntlTimeZone::createDefault();
$dateTimezone = $intlTimezone->toDateTimeZone();
$calendar = new \IntlGregorianCalendar($intlTimezone, $locale);
$dateFormatter = \IntlDateFormatter::create($locale, 2, -1, $intlTimezone, $calendar, "dd.MM.y");

$time = DateTimeImmutable::createFromFormat("Y-m-d", "978-12-27", $dateTimezone);
var_dump($time);
var_dump($time->format("d.m.Y"));
var_dump($dateFormatter->format($time));

您可以在 3v4l.org 上看到它:https://3v4l.org/tXVgn

这是输出:

object(DateTimeImmutable)#5 (3) {
    ["date"]=>
    string(26) "0978-12-27 14:31:03.000000"
    ["timezone_type"]=>
    int(2)
    ["timezone"]=>
    string(3) "CET"
}
string(10) "27.12.0978"
string(9) "22.12.978"

最后一个值似乎有误。 另请注意,PHP <= 7.0.33 无法格式化它并且 returns false.

createFromFormat 函数似乎使用了 prolectic Gregorian calendar,它将我们当前使用的日历应用于旧日期。日期格式似乎使用实际使用的儒略历。对于978,两者相差5天。

奇怪的是,我在文档中找不到任何内容可以指定哪个 class 使用哪个日历或哪个日期被视为两个日历系统之间的截止日期。