Bug #78827 [Com]: Wrong timestamp

From: Date: Fri, 29 Nov 2019 18:53:29 +0000
Subject: Bug #78827 [Com]: Wrong timestamp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223953@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78827&edit=1 ID: 78827 Comment by: leo dot sjoberg at gmail dot com Reported by: obreham at gmail dot com Summary: Wrong timestamp Status: Open Type: Bug Package: Date/time related Operating System: Ubuntu 16.04.6 LTS PHP Version: 7.3.11 Block user comment: N Private report: N New Comment: I can confirm that this is a more general problem that occurs when using strtotime("last $x + $n") where $x is the current weekday, and $n >= 7. e.g running it with "last saturday + 7 days" on a saturday will yield the same results. Note that it only happens for positive numbers greater than or equal to 7, and does not occur for negative numbers. I'm looking through the source now to see if I can find anything relating to this. Previous Comments: ------------------------------------------------------------------------ [2019-11-23 13:56:31] obreham at gmail dot com No matter what 'last Sunday' means, when you add '7 day' to it, it should yield 1 more day when compared to adding '6 day' to it; not 8 days. I've been also looking at the documentation (https://www.php.net/manual/en/datetime.formats.relative.php), which gives the following caution: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ «Also observe that the "of" in "ordinal space dayname space 'of' " and "'last' space dayname space 'of' " does something special. [...] "'last' dayname" takes the last dayname from the current day. (Example: "last wed july 2008" means "2008-06-25"; "july 2008" first sets the current date to "2008-07-01" and then "last wed" moves to the previous Wednesday which is "2008-06-25").» ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ But that doesn't explain why 'last Sunday' means something different in 'last Sunday + 6 day' and 'last Sunday + 7 day'. Note that 'last Sunday + 6 day', calculated on a Sunday, should return the equivalent of 'yesterday' or 'last Saturday' (and it does). And 'last Sunday + 7 day', calculated on a Sunday, should return the equivalent of 'today'. It actually returns 'next Sunday'. ------------------------------------------------------------------------ [2019-11-23 09:08:26] cmb@php.net Isn't that suppossed to be Sunday last week instead of `last Sunday`? ------------------------------------------------------------------------ [2019-11-17 21:22:48] obreham at gmail dot com Description: ------------ --- From manual page: https://php.net/function.strftime --- When adding a time interval to 'last Sunday' on a Sunday, you get an incorrect timestamp when interval is longer than a week. 'last Sunday' becomes 'this Sunday'. Test script: --------------- /* Example code was run on Sunday Nov 17, 2019 */ var_dump( $saturday = strtotime('last Saturday'), (strtotime('last Saturday + 1 day') - $saturday) / 86400, (strtotime('last Saturday + 2 day') - $saturday) / 86400, (strtotime('last Saturday + 3 day') - $saturday) / 86400, (strtotime('last Saturday + 4 day') - $saturday) / 86400, (strtotime('last Saturday + 5 day') - $saturday) / 86400, (strtotime('last Saturday + 6 day') - $saturday) / 86400, (strtotime('last Saturday + 7 day') - $saturday) / 86400, (strtotime('last Saturday + 8 day') - $saturday) / 86400, (strtotime('last Saturday + 9 day') - $saturday) / 86400, $sunday = strtotime('last Sunday'), (strtotime('last Sunday + 1 day') - $sunday) / 86400, (strtotime('last Sunday + 2 day') - $sunday) / 86400, (strtotime('last Sunday + 3 day') - $sunday) / 86400, (strtotime('last Sunday + 4 day') - $sunday) / 86400, (strtotime('last Sunday + 5 day') - $sunday) / 86400, (strtotime('last Sunday + 6 day') - $sunday) / 86400, (strtotime('last Sunday + 7 day') - $sunday) / 86400, (strtotime('last Sunday + 8 day') - $sunday) / 86400, (strtotime('last Sunday + 9 day') - $sunday) / 86400, $monday = strtotime('last Monday'), (strtotime('last Monday + 1 day') - $monday) / 86400, (strtotime('last Monday + 2 day') - $monday) / 86400, (strtotime('last Monday + 3 day') - $monday) / 86400, (strtotime('last Monday + 4 day') - $monday) / 86400, (strtotime('last Monday + 5 day') - $monday) / 86400, (strtotime('last Monday + 6 day') - $monday) / 86400, (strtotime('last Monday + 7 day') - $monday) / 86400, (strtotime('last Monday + 8 day') - $monday) / 86400, (strtotime('last Monday + 9 day') - $monday) / 86400 ); Expected result: ---------------- int(1573880400) int(1) int(2) int(3) int(4) int(5) int(6) int(7) int(8) int(9) int(1573362000) int(1) int(2) int(3) int(4) int(5) int(6) int(7) int(8) int(9) int(1573448400) int(1) int(2) int(3) int(4) int(5) int(6) int(7) int(8) int(9) Actual result: -------------- int(1573880400) int(1) int(2) int(3) int(4) int(5) int(6) int(7) int(8) int(9) int(1573362000) int(1) int(2) int(3) int(4) int(5) int(6) int(14) int(15) int(16) int(1573448400) int(1) int(2) int(3) int(4) int(5) int(6) int(7) int(8) int(9) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78827&edit=1

« previous php.bugs (#223953) next »