php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72719 Relative datetime format ignores weekday on sundays only
Submitted: 2016-07-31 10:14 UTC Modified: 2017-02-12 20:19 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:3 (75.0%)
From: filip at prochazka dot su Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.1.0beta1 OS: Linux
Private report: No CVE-ID: None
 [2016-07-31 10:14 UTC] filip at prochazka dot su
Description:
------------
https://3v4l.org/hrZsA

It works as expected at monday to saturday. But on sunday, it always returns monday no matter what weekday you give it, except sunday, that one works.

Test script:
---------------
var_dump(new DateTimeImmutable('Monday next week 13:00'));
var_dump(new DateTimeImmutable('Tuesday next week 14:00'));
var_dump(new DateTimeImmutable('Wednesday next week 14:00'));
var_dump(new DateTimeImmutable('Thursday next week 15:00'));
var_dump(new DateTimeImmutable('Friday next week 16:00'));
var_dump(new DateTimeImmutable('Saturday next week 17:00'));
var_dump(new DateTimeImmutable('Sunday next week 18:00'));

Expected result:
----------------
2016-08-08 13:00:00
2016-08-09 14:00:00
2016-08-10 14:00:00
2016-08-11 15:00:00
2016-08-12 16:00:00
2016-08-13 17:00:00
2016-08-14 18:00:00

Actual result:
--------------
Output for 5.6.23 - 5.6.24, 7.0.8 - 7.1.0beta1
2016-08-01 13:00:00
2016-08-01 14:00:00
2016-08-01 14:00:00
2016-08-01 15:00:00
2016-08-01 16:00:00
2016-08-01 17:00:00
2016-08-07 18:00:00

Output for 5.6.0 - 5.6.22, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.7
2016-08-08 13:00:00
2016-08-09 14:00:00
2016-08-10 14:00:00
2016-08-11 15:00:00
2016-08-12 16:00:00
2016-08-13 17:00:00
2016-08-14 18:00:00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-31 10:18 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2016-07-31 10:18 UTC] requinix@php.net
Take a look at bug #72514.
 [2016-07-31 10:45 UTC] filip at prochazka dot su
-Summary: Broken classes inherited from DatePeriod +Summary: Relative datetime format ignores weekday on sundays only
 [2016-07-31 10:45 UTC] filip at prochazka dot su
Fixed the title, as the preview function on bugs.php.net is buggy and reset's it when you click edit the preview :-/
 [2016-07-31 10:48 UTC] filip at prochazka dot su
Thanks Damian, didn't find that one :-/

Anyway, I don't like that it's closed, as this broke BC in patch version. Would be acceptable in 7.1, but look at the versions in the actual output. I'm pretty sure that's wrong.
 [2016-08-01 08:07 UTC] filip at prochazka dot su
Also, I think you've overlooked an important detail. The provided code is broken on every Sunday, but for example today, it's working according to my expectation :) 

This inconsistency is a big problem, since you can write something at Tuesday and it works, so you deploy it at Friday and on Sunday it breaks.
 [2016-08-01 14:13 UTC] requinix@php.net
-Status: Duplicate +Status: Verified -Assigned To: +Assigned To: derick
 [2016-08-01 14:13 UTC] requinix@php.net
No, you're right: this is a bug. I got hung up on the Sunday/Monday week issue and missed the different result seen only on Sundays.

Old behavior (pre-PHP 5.6.23/7.0.8), Sunday and Monday were considered part of the same week but Monday was the start of the week. This was clearly a bug (bug #63740). New behavior is that Sunday and Monday are in different weeks. https://3v4l.org/nXoDJ

However it appears that the fix introduced what you're seeing now. On a Sunday, "$dayname $reltext week" effectively ignores the $dayname.

https://3v4l.org/qv8vI - Sunday behaves differently than the rest of the week
https://3v4l.org/XtSCi - no difference between "$dayname next week" and "next week $dayname"
https://3v4l.org/fmCoi - unsurprisingly, "this week" has the same problem
 [2016-08-01 15:43 UTC] derick@php.net
> However it appears that the fix introduced what you're seeing now. On
> a Sunday, "$dayname $reltext week" effectively ignores the $dayname.

It should do that on every weekday if the current day is that weekday.

> no difference between "$dayname next week" and "next week $dayname"

That is correct too. The order does not matter. The whole string is parsed in one go. Elements in it, are not applied in order.

Relative to Sun 2016-07-31 
Mon next week = Mon 2016-08-01 
Tue next week = Mon 2016-08-01 
Wed next week = Mon 2016-08-01 
Thu next week = Mon 2016-08-01 
Fri next week = Mon 2016-08-01 
Sat next week = Mon 2016-08-01 
Sun next week = Sun 2016-08-07

This indeed looks like a bug. I will need to check that.
 [2017-02-12 20:19 UTC] derick@php.net
-Status: Verified +Status: Closed
 [2017-02-12 20:19 UTC] derick@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC