Bug #80913 [NEW]: DateTime(Immutable)::sub around DST yield incorrect time

From: Date: Mon, 29 Mar 2021 07:43:44 +0000
Subject: Bug #80913 [NEW]: DateTime(Immutable)::sub around DST yield incorrect time
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233036@lists.php.net to get a copy of this message
From:             acm at tweakers dot net
Operating system: all
PHP version:      8.0.3
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime(Immutable)::sub around DST yield incorrect time

Description:
------------
DateTimeImmutable and DateTime with a time like '2021-03-28 03:00:00' in
'Europe/Amsterdam' (i.e. the moment of the DST-transition) will give the
wrong time when substracting less than an hour. 

The same goes for all times that will give a result within an hour from
03:00+02:00.

I.e. when substracting 30 minutes, you get the same time as when
_adding_ (+60-30 = ) 30 minutes.

And the same when using DateTimeImmutable. The before-output should be
01:30+01:00.

https://3v4l.org/ZZjvq (DateTimeImmutable)
https://3v4l.org/v3u2v (DateTime)

Btw substracting 60 minutes gives the exact same time again
(03:00:00+02:00), while substracting 61 minutes correctly gives
"2021-03-28T00:59:00+01:00".

Test script:
---------------
$date = new DateTime('2021-03-28 03:00:00', new
DateTimeZone('Europe/Amsterdam'));
$_30mbefore = (clone $date)->sub(new DateInterval('PT30M'));
$_30mafter = (clone $date)->add(new DateInterval('PT30M'));

var_dump($date->format(DATE_ATOM));
var_dump($_30mbefore->format(DATE_ATOM));
var_dump($_30mafter->format(DATE_ATOM));



Expected result:
----------------
string(25) "2021-03-28T03:00:00+02:00"
string(25) "2021-03-28T01:30:00+01:00" (correct)
string(25) "2021-03-28T03:30:00+02:00"

Actual result:
--------------
string(25) "2021-03-28T03:00:00+02:00"
string(25) "2021-03-28T03:30:00+02:00" (incorrect)
string(25) "2021-03-28T03:30:00+02:00"

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80913&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80913&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80913&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80913&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80913&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80913&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80913&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80913&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80913&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80913&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80913&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80913&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80913&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80913&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80913&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80913&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80913&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80913&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#233036) next »