php / php/php-src

DateTime modify function not respect Time Zone

Open
#14,661 4 comments 2 reactions 1 assignee View on GitHub

@derickr is already working on this.

Since Jul 1, 2024.

Bug Extension: date Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
var_dump((new DateTime())->modify("2024-06-21T13:03:20-04:00"));

Resulted in this output(php >=8.2.5; >=8.3.0):

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2024-06-21 13:03:20.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}

But I expected this output instead(this works on php 8.2.4, 8.2.3, 8.2.2):

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2024-06-21 13:03:20.000000"
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "-04:00"
}
PHP Version

=8.2.5; >=8.3.0;

Operating System

Any Linux or Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.