Welcome to Geeklog, Anonymous Friday, January 10 2025 @ 01:54 pm EST

Geeklog Forums

Multiple Time Zones?


Timbo

Anonymous
mellow
Hi everyone

Has anyone ever tried putting multiple timezones in the header of a geeklog template before? Can someone help me

I have fisitors to my site from all over the world, and need to show 3 or for different timezones in the header or some where on the front page.

Anyone got any ideas?

Timbo

 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
If you don't want users to specify which time zones they have, and just provide selected timezones, here's a way I've just came up with:

In system/lib-custom.php -
function CUSTOM_templateSetVars :

(based on v1.4.1)
Text Formatted Code

    if ($templatename == 'header') {
// custom code - start
    global $_CONF;

if( !ini_get( 'safe_mode' ) &&
        function_exists( 'putenv' )) {
$date = time();

$selectedtimes = '';

$selectedtime = array(
'America/New_York',
'tokyo' => 'Asia/Tokyo',
'jerusalem' => 'Asia/Jerusalem'
);

  foreach ($selectedtime as $key => $value) {
    putenv( 'TZ=' . $selectedtime);
    $selectedtimes .= '<br>' . str_replace('_', ' ',substr($value, strpos('/') +
strlen('/'))) . ': ' . COM_getUserDateTimeFormat($value)[0];
  }
    $template->set_var( 'selectedtimes', $selectedtimes );

if( !empty( $_CONF['timezone'] )
putenv( 'TZ=' . $_CONF['timezone'] );

}
// custom code - end
    }

 

In header.thtml :
Text Formatted Code

                                <a href="{site_url}">{welcome_msg}</a><br>{datetime}
// custom code - start
                                {selectedtimes}
// custom code - end

 

Notes:
  1. I have hardcoded the display in English. If you really want, I can add language support and I don't mean via the language files (would you really want to add the word Tokyo,etc. to each and every language file...and then again if you ever add/remove a selected time?).
  2. I've had to redefine time() so you'll miss a second or two between Geeklog's default time and the selected times. Not that critical I think.
 Quote

Timbo

Anonymous
happy
Hey dude

Awesome, thanks

That is exactly what I am looking for.

Thanks

Timbo
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
I've forgot to put back the original timezone after the whole thing is done...now it's fixed.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Just realized there's a catch. If $_CONF['timezone'] isn't defined (which is the default), then I have no way that I can think of to tell what is the default timezone in order to get it back once the whole thing is done.

I guess there's a system requirement for this hack: define $_CONF['timezone'].
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by LWC: In public_html/lib-common.php -
function COM_siteHeader :

Of course, things like this should go into lib-custom.php, where we have a function CUSTOM_templateSetVars precisely for the purpose of adding your own variables to header.thtml

bye, Dirk
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
...in the beta of v1.4.1.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Nope, it's also in 1.4.0 (at least - can't remember when it was added).

bye, Dirk
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Oops, seems like it was added in v1.4.0b1 but then the sample function is weirder - "if (isset($mycontent))" makes no sense (and indeed you removed it in the beta of v1.4.1).

I've changed the hack, but I wonder how how much more the selected times would differ from Geeklog's default now that they're set in different places (originally, I've set them just one line after the default was set).
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
That function is called from within COM_siteHeader (indirectly, via PLG_templateSetVars), so it can't be that bad.

bye, Dirk
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
I know, just meant it doesn't run one line after setting the default time as before...but I guess it's still not too bad.
 Quote

Timbo

Anonymous
cheerful
Hey Guys

Thanks, and my apologies for the delay ina reply, I have been in hospital the last week going through some more Kemo.

Yes, I was having a few hassles tweaking this to get it to work properly but have only just got my strengh to sit in front of the PC again.

Thanks guys

Timbo from Down Under
 Quote

All times are EST. The time is now 01:54 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content