Ack. This time zone and DST stuff is a lot more complicated than I first imagined. I've solved my first problem - how to highlight the current day on a calendar - by using javascript to tell PHP what day it actually is on the client machine.
HOWEVER, The problem I'm facing now is that I need my server to determine what the current time is (as in the time RIGHT NOW) in a variety of zip codes. Why? I am searching a list of events whose start time is specified locally. These events could happen in any one of 13 different time zones: -12, -11, -10, -9, -8, -7, -6, -5, -4, 1, 9, 10, 11,
I have made some progress. I have a database table full of zip codes. Each zip has a timezone offset value which looks pretty much exactly like what you see in the Windows XP time settings.
For instance, I'm in california so my Win XP time zone setting is (GMT -08:00) Pacific Time (US & Canada); Tijuana
My database has an entry for my zip code that says
zip: 90046
time_zone_offset: -8
They match!
Now the problem is that my server (which is also in california) is currently reporting a GMT offset of 7 hours. This code:
<?
$now = time()
?>
Current GMT Offset in hours: <?=date('O', $now) ?><br>
Current Date and Timezone: <?=date('D, j M Y H:i:s T', $now) ?><br>
Outputs this:
Current GMT Offset in hours: -0700
Current Date and Timezone: Mon, 9 Oct 2006 21:14:18 PDT
I think the culprit here is Daylight Savings Time. On my Windows XP time settings, I have that little box checked. My server is apparently adjusting for DST too. Both Javascript and my server report -7:00 hours GMT rather than -8:00 hours GMT.
I just checked the doc entry for date
http://php.net/date
and noticed that 'I' can tell me whether DST is in effect or not for a date. I think that might offer me a way out of this but I'm having a bit of trouble getting my head around this notion.
Is this correct?
$dst = date('I', $now);
if ($dst == 1) {
echo 'DST IN EFFECT. Your offset from GMT will be +1, meaning that california time is -7 instead of -8<br>';
} else {
echo 'NO DST. Use the default offset in your database.<br>';
}
I'm still stumbling through the logic. Is there some simple way to keep track of this stuff?