Page MenuHomePhabricator

Block expiry time displayed in the logs is based on the Unix epoch instead of current time (e.g. an expiry of "10 september" displays as "00:00, 10 September 1970")
Closed, ResolvedPublic

Description

How to reproduce:

Type "10 september" into the expiry box on Special:Block (if this date has passed, increase it)

Go back to the log entry for that block, and you see a year of 1970.

Expected result: Year should be 2013

09:17, 8 September 2013 Legoktm (talk | contribs | block) blocked Legosock (talk | contribs) (autoblock disabled) with an expiry time of 00:00, 10 September 1970 (testing a bug) (unblock | change block)

Note that this doesn't affect the actual block, which uses the intended expiry. This can be confirmed by looking at [[Special:BlockList]] (https://en.wikipedia.org/wiki/Special:BlockList?wpTarget=Legosock&limit=50) or via the API: https://en.wikipedia.org/w/api.php?action=query&list=logevents&letype=block&lelimit=100&format=jsonfm&letitle=User:Legosock

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:00 AM
bzimport set Reference to bz53907.
bzimport added a subscriber: Unknown Object (MLST).
Tgr renamed this task from Entering "10 september" displays a block expiry time of "00:00, 10 September 1970" to Block expiry time displayed in the logs is based on the Unix epoch instead of current time (e.g. an expiry of "10 september" displays as "00:00, 10 September 1970").Nov 4 2016, 9:37 PM
Tgr updated the task description. (Show Details)
Tgr set Security to None.
Tgr added subscribers: matmarex, binbot, Aklapper, Tgr.

@matmarex said on wikitech-l:

The problem seems to be in the block log formatter. BlockLogFormatter::getMessageParameters() calls Language::translateBlockExpiry() to format the string "2 months" (and translate it). That in turn uses strtotime() to parse this value, and does not specify the $now parameter correctly, so January 1, 1970 is assumed. And two months, counting from January 1, 1970, is 59 days. Two months counting from today, when you made the block, is 61 days, and this correctly appears everywhere else (the block expires 2017-01-04T06:30:06Z).

BlockLogFormatter::getMessageParameters() and Language::translateBlockExpiry() should probably be fixed to use the date when the block was made for the $now parameter of strtotime().

I don't think fixing this issue should be terribly difficult, so I'm adding the good first task tag. Adding some test coverage would really help here, I imagine.

Change 332764 had a related patch set uploaded (by Bartosz Dziewoński):
BlockLogFormatter: Durations are relative to block's timestamp, not Unix epoch

https://gerrit.wikimedia.org/r/332764

Change 332764 merged by jenkins-bot:
BlockLogFormatter: Durations are relative to block's timestamp, not Unix epoch

https://gerrit.wikimedia.org/r/332764