Manual talk:Timezone
From MediaWiki.org
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).
Contents |
[edit] Background
This article was inspired by a recent install of MediaWiki and an unsuccessful attempt to set the global Timezone to something other than UTC. After finding several broken, incomplete and incorrect pages it became apparent that a Help:Timezone page was badly needed.
The primary working method was taken from a previous article and from this wikitech email authored by Brion Vibber.
It was tested on a system with the following Versions:
* MediaWiki: 1.5.6 * PHP: 4.3.11 (apache) * MySQL: 4.1.13-standard
The unconfirmed methods were tested unsuccessfully on the same system but included for further testing. Locker 09:55, 2 March 2006 (UTC)
I tried these on MediaWiki: 1.6.7, PHP: 4.3.5 (cgi), MySQL: 4.1.11-Debian_4sarge2-log, CEST time zone. By default, both logs and signatures show UTC.
- Using the primary method (with "Europe/Budapest") does absolutely nothing (except for changing the "(UTC)" text in the signature).
- Adding Date("I") as suggested does nothing either.
- Using only the $wgLocalTZoffset = date("Z") / 3600; line and nothing else leaves server time unchanged, and sets local time to server time +2. This gives correct CEST time in recentchanges and logs (including the deletion log; I dind't test the upload log), but still UTC in signatures.
--Tgr 07:21, 20 July 2006 (UTC)
My host probably didn't support the tz database. Primary method works fine, but I had to support time zone and DST manually. Rules for that can be found here. --Tgr 08:54, 20 July 2006 (UTC)
[edit] Use localtime
I'm using MediaWiki 1.6.6. I have tried the method mentioned in Help:Timezone and the time displayed successfully in history and recentchanges. The signature is not affected, but it always shows the correct time, regardless I change the $wgLocaltimezone or not. How is the mechanism in MediaWiki so that there are two different time functions? How to fix this? It is very critical because whenever I use the {{CURRENTTIME}} magic word, it points to the wrong time. TIA --Semut 13:18, 1 June 2006 (UTC)
- {{CURRENTTIME}} always shows UTC time. Use {{LOCALTIME}} instead. See: http://en.wikipedia.org/wiki/Help:Variable#Varying_with_time -- Mårten 193.200.150.167 18:28, 26 October 2008 (UTC)
[edit] Server May Crash..!! <Apache: 2.2 | MediaWiki: 1.8.0 | PHP: 5.1.4>
It works, but the server may crash.
My environment:
-
- Windows XP sp2
- AppServ 2.5.6
- Apache: 2.2
- PHP: 5.1.4 (apache2handler)
- MySQL: 5.0.22-community-nt-log)
- MediaWiki: 1.8.0
--Chlon 03:55, 16 October 2006 (UTC)
[edit] Really!
I confirm the existence of that problem. When I tried that primary method I got error: "An unhandled win32 exception occured in Apache.exe [2320]." My environment:
-
- Windows XP sp1
- Apache: 2.0.59 (Win32)
- PHP: 5.2.0
- MySQL: 5.0.27-community-nt
- MediaWiki: 1.8.2
- Windows XP sp1
Experimentally I found out, that probably the line $wgLocalTZoffset = date("Z") / 60; is causing problem. CodeMonk 00:03, 28 November 2006 (UTC)
[edit] Confirmed
I can also confirm site failure (PHP has encountered an Access Violation at 7C81BD02) when this directive is set.
- OS: Windows Server 2003 SP2
- Web: Internet Information Services 6
- PHP: 5.2.1
- MySQL: 5.0.37-community-nt
- MediaWiki: 1.10.1
IIS and MySQL must be restarted to clear this error.
[edit] Does not work on my MediaWiki 1.10.0 upgrade!
Used the code to no avail. It does not work since I upgraded from 1.6.10.
$wgLocaltimezone = "Asia/Jerusalem";
$oldtz = getenv("TZ");
putenv("TZ=$wgLocaltimezone");
# Versions before 1.7.0 used $wgLocalTZoffset as hours.
# After 1.7.0 offset as minutes
$wgLocalTZoffset = date("Z") / 3600;
putenv("TZ=$oldtz");
date_default_timezone_set("Asia/Jerusalem");
I'm lost now. Nate, 89.1.57.35 23:51, 6 June 2007 (UTC)
- Signatures on talk pages will show correct time, Special:Recentchanges shows the same edit using wrong time! Nate, 89.1.57.35 00:08, 7 June 2007 (UTC)
-
- I don't know what happened, but as I was playing with editing it, putting stuff on an off again, suddenly this agreed to work.
$wgLocaltimezone = "Asia/Jerusalem";
$oldtz = getenv("TZ");
putenv("TZ=$wgLocaltimezone");
# Versions before 1.7.0 used $wgLocalTZoffset as hours.
# After 1.7.0 offset as minutes
$wgLocalTZoffset = date("Z") / 60;
putenv("TZ=$oldtz");
-
- Date("Z") returns seconds, previous division by 3600 was giving hours, but as the specification says we are now to use minutes - division by 60. Funny thing is I already tried it before. Don't know why this time it caught on. Very weird. Nate, 89.1.57.35 02:06, 7 June 2007 (UTC)
Note that the above conversation may have been edited or added to since the transfer. If in doubt, check the edit history.
[edit] Seriously?
Is there really a 5 line php-patch necessary to display the time normally? Isn't there a Special:Timezone page yet, where i can tell the wiki to use the servertime?
[edit] Server time != mediaWiki-time
Hi there, my server seems to be in the correct time, correct time zone and tht php.ini is adjusted as well to my timezone. The mediaWiki on the server however displays in the preferences, that the server is minus two hours of what it shows. How can this be? I am in Europe/Berlin timezone. --Thekryz 16:50, 24 May 2008 (UTC)
- It seems that the server time that the MediaWiki displays, always is the UTC time. -- Mårten 193.200.150.167 18:53, 26 October 2008 (UTC)
[edit] Daylight saving time
Hi there, I tried every method described in this manual to make my MediaWiki 1.8.2 on Windows XP SP2 take daylight saving time into account, but didn't succeed. The problem was not in wrong server timezone, PHP date() function returned correct time. The fact is that MediaWiki uses UTC time internally, and every user has his own time shift. So if user's local time is re-adjusted because of daylight saving time, every user must manually re-adjust that shift in individual settings. That's a correct way, but it can't be done automatically. The wrong way will be to adjust user's time shift during daylight saving time automatically, though daylight saving is not used in many countries. In that case adjusting $wgLocalTZoffset variable won't help (and there is also a bug in userAdjust() function in Language.php in my 1.8.2), so this must be done in Language.php file:
} else {
$hrDiff = intval( $tz );
}
$hrDiff += date("I");
# No difference ? Return time unchanged
if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; }
Just add the bold line in that code fragment. After that, user's time shift will be silently re-adjusted during daylight saving time, as it is set on the server. I guess, this will work not only in 1.8.2. Best regards, CodeMonk 02:30, 18 June 2008 (UTC)
[edit] DST on server in your own timezone
If you have your MediaWiki on a server in your own timezone, nothing mentioned in this article, but the following line in LocalSettings.php was needed for me to get the correct time, including correct behaviour during DST shifts (daylight saving time):
$wgLocalTZoffset = date("Z") / 60;
Then you don't have to use $wgLocaltimezone to get correct times on signatures, since MediaWiki uses the server's time by default if $wgLocaltimezone is not defined, and the server normally knows when to go on/off DST. However $wgLocalTZoffset has to be used as above to get correct times on edits, since the default value on $wgLocalTZoffset is UTC time. Since date("Z") picks the time from the server, again DST is taken care of duly. -- Mårten 193.200.150.167 18:53, 26 October 2008 (UTC)
[edit] OMG
Holy cow, I have to read a book on how to change timezone. common.

