php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76554 DateTimeImmutable::format() returns invalid result for DST date time
Submitted: 2018-06-30 09:20 UTC Modified: 2018-06-30 10:59 UTC
From: learncomp at mail dot ru Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.3.0alpha2 OS: Linux, 4.16.13-2-ARCH
Private report: No CVE-ID: None
 [2018-06-30 09:20 UTC] learncomp at mail dot ru
Description:
------------
Europe/Oslo has DST and it occurs at (got with `(new DateTimeZone("Europe/Oslo"))->getTransitions()`):

```
     [
       "ts" => 1521939600,
       "time" => "2018-03-25T01:00:00+0000",
       "offset" => 7200,
       "isdst" => true,
       "abbr" => "CEST",
     ],
     [
       "ts" => 1540688400,
       "time" => "2018-10-28T01:00:00+0000",
       "offset" => 3600,
       "isdst" => false,
       "abbr" => "CET",
     ],
```

The following test script increments the input date time to 1 hour which should not occur?. I'm not sure either this is a bug or not as I don't have enough information to decide but probably it can be the bug.

Test script:
---------------
<?php
// For the start date time + 1 hour it prints 2018-03-25 03:00:00, which is incorrect?
echo (new \DateTimeImmutable('2018-03-25 02:00:00', new \DateTimeZone('Europe/Oslo')))->format('Y-m-d H:i:s');

// However for the end date time it does not change the value, tried for the dates: "2018-10-27 23:00:00", "2018-10-28 00:00:00", "2018-10-28 01:00:00", "2018-10-28 02:00:00", "2018-10-28 03:00:00", "2018-10-28 04:00:00", "2018-10-28 05:00:00", "2018-10-28 06:00:00" like so:
// echo (new \DateTimeImmutable('2018-10-28 03:00:00', new \DateTimeZone('Europe/Oslo')))->format('Y-m-d H:i:s');
// It always returns the same value, which I think is correct.


Expected result:
----------------
2018-03-25 02:00:00

Actual result:
--------------
2018-03-25 03:00:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-30 09:30 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-06-30 09:30 UTC] requinix@php.net
Can you remind me exactly what happens at the moment spring DST begins?
 [2018-06-30 10:42 UTC] learncomp at mail dot ru
@requinix@php.net, then why it is not changed at the end date - "2018-10-28T01:00:00+0000"?
 [2018-06-30 10:59 UTC] requinix@php.net
Does your clock show 2am when DST starts? No, because the spring DST transition does not have a 2am. If you ask PHP for 2am at that moment then it will assume you meant 3am during DST.

Does your clock show 2am when DST ends? Yes, because the fall DST transition does have a 2am. If you ask PHP for 2am at that moment then PHP assumes you meant 2am standard time. There are actually two 2am times, so if you don't give an explicit UTC offset (eg, CET or CEST) then PHP chooses the one during standard time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC