How do you format dates according to user preference in Mediawiki? I presume it has something to do with DateFormatter (http://svn.wikimedia.org/doc/classDateFormatter.html), but I'm not 100% sure how to make use of this class.
The extension I am working on displays, among other things, a last update time for its data. I want this time to display consistent with user preferences. Right now I am running (time() - (60*60*4)) through date(), but I feel this is a very inelegant solution.
Thank you,
Derric Atzrott
Computer Specialist
Alizee Pathology
On Mon, Jun 25, 2012 at 7:45 AM, Derric Atzrott < datzrott@alizeepathology.com> wrote:
How do you format dates according to user preference in Mediawiki? I presume it has something to do with DateFormatter (http://svn.wikimedia.org/doc/classDateFormatter.html), but I'm not 100% sure how to make use of this class.
Traditionally you would use the date(), time(), or timeanddate() methods on the Language class. These have options on whether to use the defaults or the current user's preferences.
This might usually look like: global $wgLang; $wgLang->timeanddate( $timestamp )
In more recent code if you're working on 1.20 (I'm not sure exactly when it came in), you might use the newer userTimeAndDate() methods which accept an explicit user object -- that lets you format for arbitrary users, sometimes useful for things like mail and always handy in that it's clearly marked. :)
$user = $this->getUser(); $this->getLanguage()->userTimeAndDate( $ts, $user );
-- brion
I think I once added a parser function that formats dates according to a user's preferences. It might be called "{{#dateformat}}". You could possibly steal the code that it uses.
On Tue, Jun 26, 2012 at 2:45 AM, Derric Atzrott < datzrott@alizeepathology.com> wrote:
How do you format dates according to user preference in Mediawiki? I presume it has something to do with DateFormatter (http://svn.wikimedia.org/doc/classDateFormatter.html), but I'm not 100% sure how to make use of this class.
The extension I am working on displays, among other things, a last update time for its data. I want this time to display consistent with user preferences. Right now I am running (time() - (60*60*4)) through date(), but I feel this is a very inelegant solution.
Thank you,
Derric Atzrott
Computer Specialist
Alizee Pathology
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org