Re: Users' time - Not Server time

Hi,

that will use the server time not the user's time, as the client does not send a GMT offset to the server so the server doesn't know that info about the client.

There are some ways to get around this though. One way is to run some JS on the client that sets a cookie with the current TZ in it. No doubt you can google for this. Then you can do some arithmetic in the MetaMod PHP code box and calculate the appropriate dates/times.

Note however that this requires a first page load to occur that runs the JS, and of course for that page load the MetaMod isn't going to know the results of the cookie. So the cookie would only be set for the 2nd and subsequent page loads. Would that be a problem for you?

Stephen BrandonMetaMod / Chameleon developerIf you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

As I mentioned, the 1st page that anyone requests will NOT receive the cookie, as it hasn’t been set yet (and that’s exceedingly annoying!). However, for subsequent page requests, MetaMod will be able to pick up this value and use it to calculate a TZ offset.

So in MetaMod, you could do this:

if ( isset($_COOKIE['tzoffset'] ) ) {
$offset = (int)$_COOKIE['tzoffset'];
$timestamp = time() - ($offset * 60); // imagine you are in GMT. then move to another part of the world, X hours ahead (tzoffset is -X). Then get the time of day using this new figure as the GMT date.
$localtime = (int)gmdate('Gi', $timestamp); // from 0 (midnight) to 959 (9:59AM) to 1000 (10AM) to 2359
if ($localtime >= 1600 and $localtime <= 1700) echo "it's between 4 and 5PM local time";
}

Instead of echoing something between those hours, you could instead return a module ID to be able to display that module. Please shout out if you need to detect particular days of the week etc as well as time of day, as that's a little more involved.

Voila! - local time zone support! (except for the 1st page requested…)

Stephen BrandonMetaMod / Chameleon developerIf you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod