Template talk:In use

From finiki, the Canadian financial wiki

I've used this template on a few occations. The times were wrong somehow, i.e. the template always read "7 hours ago" even immediately after being inserted. Can someone else do a test to see if the same problem occurs? Thanks --Quebec 17:53, 2 March 2015 (MST)

E.g., see the sandbox. --Quebec 18:00, 2 March 2015 (MST)
IIRC, I noticed this when I first cloned it over from Wikipedia and I never found the cause. I'll need to investigate further and see if it can be resolved. --Peculiar Investor 19:17, 2 March 2015 (MST)
I think I've found the cause, it is related to a MediaWiki configurations setting, specifically Manual:$wgLocaltimezone. Need to do further reading and testing to ensure understanding of changing this value. --Peculiar Investor 08:20, 3 March 2015 (MST)
I confirm Quebec's view; I am on America/New York (GMT - 5 hours) time and see a 2 hour difference. The template time is based on the magic word {{REVISIONTIMESTAMP}}, documented in Help:Magic words, "Technical metadata" section. The MediaWiki software is using the server's local time zone for the calculation. What's needed is the conversion to the editor's time zone preference when logged in. Manual:$wgLocaltimezone won't have an effect, as it will be a fixed offset not related to the editor's actual time zone. I don't see a magic word that utilizes the logged-in editor's time zone offset.
This is similar to viewing the time on the FWF forum. When logged in, the displayed time is correctly calculated to reflect the member's actual local time. When not logged in, the time is calculated to be the time zone as set by the site administrators (fixed offset).
I haven't tested this myself yet, but I would suggest that MediaWiki's use of magic words does not have the capability to display time based on the editor's (member's) preferences. Real-time display, as shown in the revision history and recent changes, is done correctly. --LadyGeek 18:07, 3 March 2015 (MST)

Timezone and timestamp magic words - some technical details

The "7 hours ago" is due to fact that MediaWiki stores dates in UTC, but the server is located in UTC−07:00. {{In use}} uses {{Time ago}} and compares to the magic word {{REVISIONTIMESTAMP}} timezone effect on some #time parser functions.

Here are some timestamp magic words and {{Time ago}} outputs.

  • {{REVISIONTIMESTAMP}} is 20150306051854, {{Time ago|{REVISIONTIMESTAMP}}}} is 9 years ago
  • {{CURRENTTIMESTAMP}} is 20240428144433, {{Time ago|{{CURRENTTIMESTAMP}}}} is 0 seconds ago
  • {{LOCALTIMESTAMP}} is 20240428144433, {{Time ago|{{LOCALTIMESTAMP}}}} is 0 seconds ago

The template is cloned from Wikipedia, which sets the Help:$wgLocaltimezone configuration variable to 'UTC', therefore there is no timezone offset to worry about. Still investigating a) the side effects of changing the configuration variable per Wikipedia, knowing it impacts guests or b) how to re-code the template, but then it is localized from the Wikipedia version, so further updating might become problematic.

FWIW, the problem exists on the BH wiki as well.

--Peculiar Investor 06:48, 4 March 2015 (MST)

There is a dependency on the user's Timezone preference. If not set, it defaults to the server's timezone. Based on the information above, I'm guessing that LadyGeek has set this preference and Quebec has not. --Peculiar Investor 06:53, 4 March 2015 (MST)
Found one other bug, the displayed "last revised" is not UTC, another Wikipedia specific timezone dependency. I've posted a possible solution in Sandbox. --Peculiar Investor 07:10, 4 March 2015 (MST)
Further digging into the nitty gritty of the database structure reveals some errors above, now fixed via strike-through. I think I've convinced myself that the changes demonstrated in Sandbox will resolve the problem. --Peculiar Investor 09:03, 4 March 2015 (MST)
  • The explanation for the code change to {{Time ago| {{#time: r|@{{#expr: {{#time: U| {{REVISIONTIMESTAMP}} }} - {{#timel: Z}} }} }} }}. The code uses Help:Extension:ParserFunctions, specifically the #time functions. {{Time ago}} expects a timestamp in UTC, but our server is located in UTC, so the parameter passed must be adjusted. {{#time: U| {{REVISIONTIMESTAMP}} }} converts the revision timestamp (UTC) into a Unix timestamp (in seconds) and then the Timezone offset in seconds is subtracted so now we've got it in UTC. The </nowiki>{{#time: r|@ </nowiki> then converts it back into the time format that {{Time ago}} expects. Note: MediaWiki caches some parser function values, so sometimes a Refresh is required to properly update the amount of time since the last revision. The previous logic was adding and subtracting timestamps in the wrong format, so the results were unpredictable, sometimes right, but other times returning an Error: First parameter cannot be parsed as a date or time. --Peculiar Investor 18:34, 5 March 2015 (MST)

Take a look at {{Last edited by}}, which is used by {{In creation}}. I just edited {{In creation}}, but it says "7 hours ago", which is the offset between UTC and local server time. (Check against the revision history.) --LadyGeek 18:55, 5 March 2015 (MST)

Yes check.png Done --Peculiar Investor 22:18, 5 March 2015 (MST)