php / php/php-src

`IntlDateFormatter` returns wrong output for 1940 date in Amsterdam timezone

未关闭
#10,898 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Extension: intl Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

The following code:

<?php

$timezone = new DateTimeZone("Europe/Amsterdam");
$date = new DateTime("1940-01-01 00:00:00", $timezone);
var_dump($date);

$formatter = new IntlDateFormatter("en-US");
var_dump($formatter->format($date));

Resulted in this output:

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "1940-01-01 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
string(69) "Sunday, December 31, 1939 at 11:40:00 PM Coordinated Universal Time"

But I expected this output instead:

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "1940-01-01 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
string(48) "Monday, January 1, 1940 at 12:00:00 AM GMT+00:20"

Additional details

Until 16 May 1940, The Netherlands used UTC+00:20 as timezone. It looks like IntlDateFormatter is not aware of the UTC+00:20 timezone, so it outputs the date in UTC.

The occurrence of the problem seems related to the version of the ICU library:

Environment Source PHP version ICU version Output
3v4l.org https://3v4l.org/UoVSs 8.2.4 57.1 ✅ As expected
Docker + Debian libicu Dockerfile 8.2.4 67.1 ❌ Wrong
Docker + latest libicu Dockerfile 8.2.4 72.1 ❌ Wrong

I am not familiar enough with the ICU library to assess whether the problem originates there. Since the wrong output is present in PHP when using the latest versions (of PHP and the ICU library), I am submitting the bug here.

PHP Version

8.2.4

Operating System

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用所引用的 Debian 和 latest-ICU Dockerfile,重现针对 Europe/Amsterdam 的 IntlDateFormatter 示例,并比较 issue 中列出的 ICU 版本。追踪错误的历史偏移量是来自 PHP 还是 ICU;当 formatter 返回预期的 1940 UTC+00:20 结果,或者将该 issue 记录为 ICU upstream 的限制时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
internationalization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。