Page MenuHomePhabricator

There are four parameters - adapt documentation for the ParserFunction "#time"
Closed, ResolvedPublic

Description

While working on T223003 I found out a seemingly undocumented parameter of the #time ParserFunction.

As described here https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##time , the function syntax should be {{#time: format string | date/time object | language code }}, but looking at the source code it seems to me there are actually four arguments.
The fourth is $local and controls if the time should be shown as UTC or as local time.
Take the following examples (generated on my Wikipedia sandbox page) for instance:

WikitextResult
{{#time:c|now|it}}2019-05-16T13:25:17+00:00
{{#time:c|now|it|0}}2019-05-16T13:25:17+00:00
{{#time:c|now|it|1}}2019-05-16T15:25:17+02:00

So, there is in fact a fourth parameter that behaves like this:

  • If it is empty or set to 0, the time is treated as UTC regardless of $wgLocaltimezone setting
  • If it is not empty and different from 0, the time is shown as local

First of all I want to ask for confirmation of my tests: am I correctly reading the code and understanding the work of the function?
If I am right, I would fix the documentation to explain this feature.

Thanks

Luca

Event Timeline

Restricted Application added subscribers: Liuxinyu970226, Aklapper. · View Herald TranscriptMay 16 2019, 1:49 PM
lucamauri renamed this task from Adapt documentation for the ParserFunction "#time" fourth parameter to There are four parameters - adapt documentation for the ParserFunction "#time".May 16 2019, 2:30 PM
Umherirrender added a subscriber: Umherirrender.EditedMay 16 2019, 6:44 PM

It seems easier to use #timel for it, doing the same and is documented.
Each value with is truthy in php semantic can be used, so each text makes it true, empty string, spaces or zeros makes it false.

lucamauri added a comment.EditedMay 17 2019, 6:28 AM

It seems easier to use #timel for it, doing the same and is documented.

Indeed I agree with you on this point.
Nevertheless, since #time function is there, it is conceptually correct and fair to the users for it to be properly documented and not left half-documented just because is less likely to be used.

Each value with is truthy in php semantic can be used, so each text makes it true, empty string, spaces or zeros makes it false.

Thanks for this clarification, I will surely make good note of it when updating the documentation. For everyone's reference, https://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting is detailed explanation.

I have published a revised version of the documentation in my sandbox page here https://www.mediawiki.org/wiki/User:Lucamauri/Sandbox/ParserTime
You are welcome to make suggestion on it before I replace the current version at https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##time

lucamauri closed this task as Resolved.May 29 2019, 8:30 PM

I read no comments, additions or complains in the past several days, so I proceeded updating the documentation as proposed.

Iniquity removed a project: Notice.