Bug #76634 [Com]: setISODate sets current time(date is correct)
| From: | a at b dot c dot de | Date: | Tue, 17 Jul 2018 01:33:13 +0000 |
| Subject: | Bug #76634 [Com]: setISODate sets current time(date is correct) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216358@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76634&edit=1
ID: 76634
Comment by: a at b dot c dot de
Reported by: pawlu dot kolo at yahoo dot pl
Summary: setISODate sets current time(date is correct)
Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Ubuntu 16
PHP Version: 7.0.30
Block user comment: N
Private report: N
New Comment:
Or use DateTime::setTime() to set the time (same as if you used setDate to set the date).
Previous Comments:
------------------------------------------------------------------------
[2018-07-17 00:58:38] requinix@php.net
setISODate() is meant to set the date, which is why it should not set the time as well.
Your problem is with the "new DateTime()" portion. That defaults to the current time. If
you want something repeatable then you need to give it a fixed initial date.
https://3v4l.org/6hbDZ
------------------------------------------------------------------------
[2018-07-16 17:51:52] pawlu dot kolo at yahoo dot pl
Description:
------------
I found out that setISODate function does not set timestamp as expected. It sets proper date but
time seems to be taken from current timestamp. I know that it is meant to set date but it should set
00:00:00 for time part to ensure repeatable results.
Test script:
---------------
$date='2018-06-29 00:00:00';
$startDate=(new
DateTime())->setISODate(date('Y',strtotime($date)),date('W',strtotime($date)))->format('Y-m-d
H:i:s');
$endDate=(new DateTime())->setISODate(date('Y',strtotime($date)),
date('W',strtotime($date)), 7)->format('Y-m-d H:i:s');
$startTimestamp = (new
DateTime())->setISODate(date('Y',strtotime($date)),date('W',strtotime($date)))->getTimestamp();
echo 'input = '.$date;
echo '<br/>strtotime = '.strtotime($date);
echo '<br/>setISODate->getTimestamp = ';
echo $startTimestamp;
echo '</br>startDate = '.$startDate.'<br/>endDate = '.$endDate;
Expected result:
----------------
input = 2018-06-29 00:00:00
strtotime = 1530244800
setISODate->getTimestamp = 1529899200
startDate = 2018-06-25 00:00:00
endDate = 2018-07-01 00:00:00
Actual result:
--------------
input = 2018-06-29 00:00:00
strtotime = 1530244800
setISODate->getTimestamp = 1529946301
startDate = 2018-06-25 13:05:01
endDate = 2018-07-01 13:05:01
or bit later:
input = 2018-06-29 00:00:00
strtotime = 1530244800
setISODate->getTimestamp = 1529946704
startDate = 2018-06-25 13:11:44
endDate = 2018-07-01 13:11:44
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76634&edit=1