Skip to content
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

Parser DateTime vs DateTimeZone #8872

Closed
hormus opened this issue Jun 26, 2022 · 3 comments
Closed

Parser DateTime vs DateTimeZone #8872

hormus opened this issue Jun 26, 2022 · 3 comments

Comments

@hormus
Copy link

hormus commented Jun 26, 2022

Description

The following code:

<?php
$date = new DateTime('2022-10-30 02:00:00', new DateTimeZone('Europe/Amsterdam'));
$date2 = new DateTime('2022-10-30 02:00:00 Europe/Amsterdam');
var_dump($date->format('U') == $date2->format('U'));

Resulted in this output from php 8.1.7:

false

But I expected this output instead:

true

PHP Version

php 8.1.7

Operating System

Irrelevant

@damianwadley
Copy link
Member

Looks good from here. https://3v4l.org/9Ot50

What actual timestamps are you seeing?

@hormus
Copy link
Author

hormus commented Jun 26, 2022

@damianwadley

<?php

$date = new DateTime('2022-10-30 02:00:00', new DateTimeZone('Europe/Amsterdam'));
$date2 = new DateTime('2022-10-30 02:00:00 Europe/Amsterdam');
$output_utc1 = $date->format('U');
$output_utc2 = $date2->format('U');
var_dump($output_utc1, $output_utc2, $output_utc1 == $output_utc2);
?>

Correct:
string(10) "1667091600" string(10) "1667091600" bool(true)
not Correct from php 8.1.7:
string(10) "1667091600" string(10) "1667088000" bool(false)

30 ott 2022 - Daylight Saving Time Ends
When local daylight time is about to reach
sunday 30 ottobre 2022, 3.00.00 clocks are turned backward 1 hour to
sunday 30 ottobre 2022, 2.00.00 local standard time instead. CEST to CET

1667091600 or with bug 1667088000
object(DateTime)#2 (3) { ["date"]=> string(26) "2022-10-30 02:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
With bug does not comply with the proposed rfc specification https://wiki.php.net/rfc/datetime_and_daylight_saving_time

@derickr
Copy link
Member

derickr commented Jul 28, 2022

This is a duplicate of #9165, which has a better example and is better articulated. I'm therefore closing this one.

@derickr derickr closed this as completed Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants