Welcome to Geeklog, Anonymous Friday, January 10 2025 @ 01:54 pm EST
Geeklog Forums
Multiple Time Zones?
Timbo
Anonymous
Hi everyone
Has anyone ever tried putting multiple timezones in the header of a geeklog template before?
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
Has anyone ever tried putting multiple timezones in the header of a geeklog template before?
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
8
10
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)
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 :
<a href="{site_url}">{welcome_msg}</a><br>{datetime}
// custom code - start
{selectedtimes}
// custom code - end
Notes:
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:
- 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?).
- 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.
5
6
Quote
Timbo
Anonymous
Hey dude
Awesome, thanks
That is exactly what I am looking for.
Thanks
Timbo
Awesome, thanks
That is exactly what I am looking for.
Thanks
Timbo
10
7
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'].
I guess there's a system requirement for this hack: define $_CONF['timezone'].
9
7
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 :
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
7
8
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).
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).
6
7
Quote
Timbo
Anonymous
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
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
7
8
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