Bug #80409 [Opn]: DateTime::modify() loses time with 'weekday' parameter

From: Date: Tue, 24 Nov 2020 14:20:39 +0000
Subject: Bug #80409 [Opn]: DateTime::modify() loses time with 'weekday' parameter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230581@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80409&edit=1

 ID:                 80409
 Updated by:         cmb@php.net
 Reported by:        karol dot piotr dot kolanko at gmail dot com
 Summary:            DateTime::modify() loses time with 'weekday'
                     parameter
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        7.4.12
 Block user comment: N
 Private report:     N

 New Comment:

For reference: <https://3v4l.org/m0UbY>

According to the manual this is supposed to work[1], but I have no
idea what "+1 weekday" is supposed to do.

[1] <https://www.php.net/manual/en/datetime.formats.relative.php>


Previous Comments:
------------------------------------------------------------------------
[2020-11-24 10:05:28] karol dot piotr dot kolanko at gmail dot com

Description:
------------
DateTime::modify() with parametrem 'weekday' loses time value.

Also date() function.

Test script:
---------------
<?php
$date = '2020-11-27 12:33:00';

echo date('Y-m-d H:i:s', strtotime($date.' +1 day')); 
// Correct: 2020-11-28 12:33:00
echo date('Y-m-d H:i:s', strtotime($date.' +1 Weekday'));
// Uncorrect, lost time: 2020-11-30 00:00:00

$date1 = new DateTime($date);
$date2 = new DateTime($date);

$date2->modify('+1 day');
echo $date2->format('Y-m-d H:i:s');
// Correct: 2020-11-28 12:33:00
$date1->modify('+1 weekday');
echo $date1->format('Y-m-d H:i:s');
// Uncorrect, lost time: 2020-11-30 00:00:00




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80409&edit=1


Thread (5 messages)

« previous php.bugs (#230581) next »