Unexpected Results with PHP8 date_diff for Different Timezones

Đang mở
#13,857 3 bình luận 1 reaction 1 người được giao Xem trên GitHub

@derickr đang làm issue này rồi.

Từ ngày 1/4/2024.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

Bug Extension: date Status: Verified
Description

In PHP 8.1.25, running date_diff against different time zones returned unexpected results.

https://3v4l.org/RFQMt

The following code:

<?php
date_default_timezone_set('Asia/Tokyo');
$nowDate = (new DateTime('2024-04-01 00:49:22'))->setTimeZone(new DateTimeZone('Asia/Tokyo'));
$endDate = (new DateTime('2024-04-01 08:48:22'))->setTimeZone(new DateTimeZone('UTC'));
echo date_diff($nowDate, $endDate)->format('%Y-%M-%D %H:%I:%S');

Resulted in this output:

-1-11-31 07:59:00

But I expected this output instead:

00-00-00 07:59:00
PHP Version

PHP 8.1.25

Operating System

Ubuntu 22.04

Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
103

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của php/php-src

Tất cả issue của php/php-src

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.