-
Notifications
You must be signed in to change notification settings - Fork 7.8k
DateTime modify function not respect Time Zone #14661
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
Comments
Agreed that modification of the date/time portion is incorrect, however IMO it shouldn't have the side effect of also changing the timezone. The one specified in the string should determine how to interpret its own date and time, but the DateTime instance's own timezone should be preserved. In other words, $dt = new DateTime("2024-06-21T12:00:00+00:00");
var_dump($dt);
$dt->modify("2024-06-22T12:00:00+01:00");
var_dump($dt); should output 06-21 12:00 +00 and then 06-22 11:00 +00. |
If all php versions would work this way, it won't be a problem. <?php
$date = "2024-06-22T23:00:00-04:00";
$dateObject = Carbon::createFromTimeString($date); It will work on php 8.2.4, but when changes were deployed to server with php 8.2.5, this will be problematic :-) I agree we should use brand new DateTime object : <?php
$date = "2024-06-22T23:00:00-04:00";
$dateObject = new DateTime($date);
// OR better
$dateObject = DateTime::createFromFormat(DateTimeInterface::ATOM, $date);
var_dump($dateObject ); Output:
|
Currently DateTime::modify sets UTC for syntax @ unixtimestamp from PHP 8.1.15 > and later PHP 8.2.2 > and later. Later... Other fix (PHP 8.2.5) modify('+1 s') #9891 (comment) |
Carbon is doing weird stuff here. It shouldn't be using The bug here is that extra information that isn't being used (the |
Description
The following code:
Resulted in this output(php >=8.2.5; >=8.3.0):
But I expected this output instead(this works on php 8.2.4, 8.2.3, 8.2.2):
PHP Version
Operating System
Any Linux or Windows
The text was updated successfully, but these errors were encountered: