Bathroom_Monkey wrote:
For posterity's sake, here is an algorithm I created to take a GMT
time and convert it to U.S. central time, accounting for daylight
saving time. Note: this algorithm can be modified to work for any
other U.S. timezone by changing the number of second subtracted at the
end.
<?
$in_dst="false";
if( (date(m)>=4) && (date(m)<=10) ) // IS CURRENT DATE INSIDE OF
APRIL->OCT WINDOW?
{
if( (date(m)>4) && (date(m)<10) ) //IS CURRENT DATE INSIDE
MAY->SEPT WINDOW?
{
$in_dst="true";
}
elseif($date(m)=="4") //IS IT APRIL?
{
if( (date(j)<=7) && (date(D)=="Sun") ) //IS IT THE FIRST SUN OF
THE MONTH?
{
if(date(H)>"1") //IS IT PAST 2:00AM?
{
$in_dst="true";
}
}
}
elseif($date(m)=="10") //IS IT OCT?
{
if( (date(j)<=25) && (date(D)=="Sun") ) //IS IT THE LAST SUN OF
THE MONTH?
{
if(date(H)>"1") //IS IT PAST 2:00AM?
{
$in_dst="false";
}
}
}
}
if($in_dst=="true") //INSIDE OF DST
{
$date=date("Y:m:dH:i:s",time()-18000); //CHANGE NUMBER OF SECONDS
HERE TO MODIFY
}
else //OUT OF DST
{
$date=date("Y:m:dH:i:s",time()-21600); //CHANGE NUMBER OF SECONDS
HERE TO MODIFY
}
?>
Please post any possible bugs you guys find.
this is a lot of code...
how about
:
function
isDST(/* assumes "now" */)
{
return stristr(date("T"), "daylight") != false;
}
this will return the current local setting of the *server* (therefore it
will not work on all servers -- see below)
or
given a timestamp:
$yr = date("Y", $timestamp);
$apr = strtotime("first sunday", strtotime("april 1 $yr")); // sunday >= 4/1
$oct = strtotime("last sunday", strtotime("nov 1 $yr)); // sunday before 11/1
$isDST = $timestamp > $apr && $timestamp < $oct;
you can make timestamp adjustments for timezone if you want... however,
time calcs in the same zone should suffice..
remember -- there are (at least) two areas (not entire states) in the US
that do not have DST -- one is in Arizona (MST all year) and the other
is in Indiana (EST)... so now you have the problem of location as well!
....and this doesn't even begin to scratch the surface.
DST start/end times have varied over the years and may or may not remain
static for the near future. In the 60's, I remember school driven
petitions to "standardize" daylight savings time (I was in Vermont at
the time) -- the result was the Uniform Time Act 1966 [with
exemptions!]. Different states (or even regions) would go into and out
of DST on different dates. Before WWII (WT, or war time), observance was
erratic and before and since, until (relatively) recently, it was
observed on a state by state basis.
And then there are all countries outside the US... some observe "Summer
Time" (portions of Great Britain - but does not affect GMT) or other
variants of DST and some do not. Ask any astrologer about DST and watch
them run to the aspirin bottle! There have been books published on the
subject detailing when and where and by how much savings time was used
[not *always* 1 hour! -- DST to the british means *double summer time*
-- google "double summer time" ]...
have fun!