Making Postnuke Understand Time Properly

I finally got fed up enough with the dumb way that PostNuke does its time stamping to try and fix it. Basically it uses local time everywhere, then gets you to tell it which timezone its in via its preferences and finally expects users to register and set their timezone so it can re-correct the time for them!

Anyway, this isn’t obvious until you go hunting around for why it doesn’t seem to work if you’re not in the same timezone (or in my case, continent & hemisphere) for where your website is. Googling around for Postnuke “time zone offset” gives some helpful references, especially with respect to a Postnuke Forums posting about fixing it. But before you go off and read that, note that (a) it won’t work on current versions and (b) there’s a simplified variant of the hack. Still kudos to them for working this out!

You’ll need to read on for the guts of the article, as I don’t want to scare the non-techies out there by putting it on the front page directly.. 🙂

First off, thanks again to the Postnuke Forums user who did the hard work of figuring out what the strategy was! All I’ve done is tidy it up a bit..

What you need to do is modify the file pnAPI.php in the includes directory to change the GetUserTime function to the following code. The simplification I’ve made to the one they posted is that you can use the PHP date() function to get the difference in seconds between UTC and the systems timezone, rather than working it out yourself.

if (!function_exists('GetUserTime')) {
function GetUserTime($time) {

        $tzDiff = date("Z");
	// Convert to UTC
        $time -= $tzDiff;

        if (pnUserLoggedIn()) {
                $time += (pnUserGetVar('timezone_offset') * 3600);
        else {
                $time += (pnConfigGetVar('timezone_offset') * 3600);

You’ll then need to edit the file modules/NS-Languages/api.php (where the tzinfo variable has moved to, from the old includes/legacy.php) and replace the tzinfo array with one that uses indexes based on the hour offset from UTC, viz:

$tzinfo = array('-12' => '(GMT -12:00 hours) Eniwetok, Kwajalein',
'-11' => '(GMT -11:00 hours) Midway Island, Samoa',
'-10' => '(GMT -10:00 hours) Hawaii',
'-9' => '(GMT -9:00 hours) Alaska',
'-8' => '(GMT -8:00 hours) Pacific Time (US & Canada)',
'-7' => '(GMT -7:00 hours) Mountain Time (US & Canada)',
'-6' => '(GMT -6:00 hours) Central Time (US & Canada), Mexico City',
'-5' => '(GMT -5:00 hours) Eastern Time (US & Canada), Bogota, Lima, Quito',
'-4' => '(GMT -4:00 hours) Atlantic Time (Canada), Caracas, La Paz',
'-3.5' => '(GMT -3:30 hours) Newfoundland',
'-3' => '(GMT -3:00 hours) Brazil, Buenos Aires, Georgetown',
'-1' => '(GMT -2:00 hours) Mid-Atlantic',
'-1' => '(GMT -1:00 hours) Azores, Cape Verde Islands',
'0' => '(GMT) Western Europe Time, London, Lisbon, Casablanca, Monrovia',
'1' => '(GMT +1:00 hours) CET(Central Europe Time), Brussels, Copenhagen, Madrid, Paris',
'2' => '(GMT +2:00 hours) EET(Eastern Europe Time), Kaliningrad, South Africa',
'3' => '(GMT +3:00 hours) Baghdad, Kuwait, Riyadh, Moscow, St. Petersburg',
'3.5' => '(GMT +3:30 hours) Tehran',
'4' => '(GMT +4:00 hours) Abu Dhabi, Muscat, Baku, Tbilisi',
'4.5' => '(GMT +4:30 hours) Kabul',
'5' => '(GMT +5:00 hours) Ekaterinburg, Islamabad, Karachi, Tashkent',
'5.5' => '(GMT +5:30 hours) Bombay, Calcutta, Madras, New Delhi',
'6' => '(GMT +6:00 hours) Almaty, Dhaka, Colombo',
'7' => '(GMT +7:00 hours) Bangkok, Hanoi, Jakarta',
'8' => '(GMT +8:00 hours) Beijing, Perth, Singapore, Hong Kong, Chongqing, Urumqi, Taipei',
'9' => '(GMT +9:00 hours) Tokyo, Seoul, Osaka, Sapporo, Yakutsk',
'9.5' => '(GMT +9:30 hours) Adelaide, Darwin',
'10' => '(GMT +10:00 hours) EAST(East Australian Standard)',
'11' => '(GMT +11:00 hours) Magadan, Solomon Islands, New Caledonia',
'12' => '(GMT +12:00 hours) Auckland, Wellington, Fiji, Kamchatka, Marshall Island');

Leave a Reply

Your email address will not be published. Required fields are marked *