Page MenuHomePhabricator

Off-by-one error in #time parserfunction calculation for the day of the week
Closed, InvalidPublic

Description

Live Demonstration of the problem: https://meta.wikimedia.org/w/index.php?title=User:Quiddity_(WMF)/sandbox2&oldid=19276915


Context:
We've been using this code to write Tech News for a few years (using this init page as preload), and I think it used to work correctly(?).
But for the last few months (IIRC), it does everything off-by-one.


Copy of the table in the Demonstration link, for posterity. (Note: this is using ! instead of | because pipes are phab-markup for tables):

CodeCode-Generated ResultShould actually be (manually written)
{{#time:Y-m-d ! 2019-W34, Monday}}2019-08-252019-08-19
{{#time:Y-m-d ! 2019-W34, Tuesday}}2019-08-192019-08-20
{{#time:Y-m-d ! 2019-W34, Wednesday}}2019-08-202019-08-21
{{#time:Y-m-d ! 2019-W34, Thursday}}2019-08-212019-08-22

Event Timeline

Quiddity created this task.Fri, Aug 9, 6:38 PM
Restricted Application added subscribers: Liuxinyu970226, Aklapper. · View Herald TranscriptFri, Aug 9, 6:38 PM
Quiddity moved this task from Backlog to #time on the ParserFunctions board.Fri, Aug 9, 6:39 PM

Not a bug IMO, proposing to close as invalid (plus PHP, not MediaWiki). Use 2019-W01-2 instead of borked 2019-W01, Tuesday (where does that come from?).

$:acko\> rpm -q php
php-7.3.8
$:acko\> cat test.php 
<?php
echo strtotime("2019-W01, Sunday"), "\n";
echo strtotime("2019-W01-0"), "\n";
echo "been sunndae, now tuedae:\n";
echo strtotime("2019-W01, Tuesday"), "\n";
echo strtotime("2019-W01-2"), "\n";
?>
$:acko\> php ./test.php 
1546646400
1546128000
been sunndae, now tuedae:
1546214400
1546300800
$:acko\> date -d @1546646400
Sat 05 Jan 2019 01:00:00 AM CET
$:acko\> date -d @1546128000
Sun 30 Dec 2018 01:00:00 AM CET
$:acko\> date -d @1546214400
Mon 31 Dec 2018 01:00:00 AM CET
$:acko\> date -d @1546300800
Tue 01 Jan 2019 01:00:00 AM CET
Quiddity closed this task as Invalid.Fri, Aug 9, 8:54 PM

Not a bug IMO, proposing to close as invalid (plus PHP, not MediaWiki). Use 2019-W01-2 instead of borked 2019-W01, Tuesday (where does that come from?).

Aha! Thank you!
(They were added in this edit. I will now attempt to fix them with this edit. It looks like it worked! Thanks again.)

Restricted Application removed a subscriber: Liuxinyu970226. · View Herald TranscriptFri, Aug 9, 8:54 PM