function date_is_dst in Date 5
Same name and namespace in other branches
- 5.2 date_php4/date_php4.inc \date_is_dst()
- 6.2 date_php4/date_php4.inc \date_is_dst()
- 6 date_php4/date_php4.inc \date_is_dst()
Check if time is in Daylight Savings Time
Parameters
$region a drupal dst region code, corresponding to those from date_get_dst_regions():
$timestamp a GMT timestamp:
Return value
0 or 1
1 call to date_is_dst()
File
- ./
date_timezones.inc, line 15
Code
function date_is_dst($region, $timestamp) {
$year = date('Y', $timestamp);
$dst = date_get_dst_regions();
// Information on Daylight Saving time was obtained from http://webexhibits.org/daylightsaving/g.html
switch ($region) {
case 0:
return 0;
case 1:
// Egypt
// start of DST (last Friday in April)
$dststart = strtotime("-1 week friday GMT", strtotime("1 may {$year} GMT"));
// end of DST (last Thursday in September)
$dstend = strtotime("-1 week thursday GMT", strtotime("1 october {$year} GMT"));
break;
case 2:
// Namibia
// start of DST (first Sunday in September)
$dststart = strtotime("1 week sunday GMT", strtotime("1 september {$year} GMT"));
// end of DST (first Sunday April)
$dstend = strtotime("1 week sunday GMT", strtotime("1 april {$year} GMT"));
break;
case 3:
// Former USSR
// start of DST (last Sunday in March)
$dststart = strtotime("-1 week sunday GMT", strtotime("1 april {$year} GMT"));
// end of DST (last Sunday October)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 november {$year} GMT"));
break;
case 4:
// Iraq, Syria
// start of DST (April 1st)
$dststart = strtotime("1 april {$year} GMT");
// end of DST (October 1st)
$dstend = strtotime("1 october {$year} GMT");
break;
case 5:
// Israel
// start of DST (April 1st)
$dststart = strtotime("1 april {$year} GMT");
// end of DST (Saturday between Rosh Hashana (Oct. 4-5) and Yom Kippur (Oct. 13))
// these values are good for 2005/2006 only, hopefully a good gregorian <-> jewish conversion script can be implemented
$dstend = strtotime("-1 saturday {$year} GMT", strtotime("13 october {$year} GMT"));
break;
case 6:
// Lebanon, Kirgizstan
// start of DST (Last Sunday in March)
$dststart = strtotime("-1 week sunday GMT", strtotime("1 april {$year} GMT"));
// end of DST (Last Sunday in October)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 november {$year} GMT"));
break;
case 7:
// Palestine
// start of DST (First Friday on or after April 15th)
$dststart = strtotime("next friday GMT", strtotime("14 april {$year} GMT"));
// end of DST (First Friday on or after October 15th)
$dstend = strtotime("next friday GMT", strtotime("14 october {$year} GMT"));
break;
case 8:
// Iran
// start of DST (the first day of Farvardin (March 21))
$dststart = strtotime("21 march {$year} GMT");
// end of DST (the first day of Mehr (September 23))
$dstend = strtotime("23 september {$year} GMT");
break;
case 9:
// South Australia
// start of DST (last Sunday in October)
$dststart = strtotime("-1 week sunday GMT", strtotime("1 november {$year} GMT"));
// end of DST (last Sunday in March)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 april {$year} GMT"));
break;
case 10:
// Australia, Tasmania
// start of DST (first Sunday in October)
$dststart = strtotime("1 week sunday GMT", strtotime("1 october {$year} GMT"));
// end of DST (last Sunday in March)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 april {$year} GMT"));
break;
case 11:
// New Zealand
// start of DST (first Sunday in October)
$dststart = strtotime("1 week sunday GMT", strtotime("1 october {$year} GMT"));
// end of DST (third Sunday in March)
$dstend = strtotime("3 week sunday GMT", strtotime("1 march {$year} GMT"));
break;
case 12:
// Tonga
// start of DST (first Sunday in November)
$dststart = strtotime("1 week sunday GMT", strtotime("1 november {$year} GMT"));
// end of DST (last Sunday in January)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 february {$year} GMT"));
break;
case 13:
// EU and other European countries
// start of DST (last Sunday in March 1 am GMT)
$dststart = strtotime("-1 week sunday GMT", strtotime("1 april {$year} GMT")) + 3600;
// end of DST in Europe (last Sunday in October 1 am GMT)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 november {$year} GMT")) + 3600;
break;
case 14:
// Russian Federation
// start of DST (last Sunday in March 2 am local time)
$dststart = strtotime("-1 week sunday GMT", strtotime("1 april {$year} GMT")) + 7200;
// end of DST (last Sunday in October 2 am local time)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 november {$year} GMT")) + 7200;
break;
case 15:
// Northern America (where applicable)
// start of DST (where applicable) (first Sunday in April before 2007,
// after that second Sunday in March, 2 am local time)
$dststart = strtotime("1 week sunday GMT", strtotime("1 april {$year} GMT")) + 7200;
if ($year < 2007) {
$dststart = strtotime("0 week sunday GMT", strtotime("1 april {$year} GMT")) + 7200;
}
else {
$dststart = strtotime("1 week sunday GMT", strtotime("1 march {$year} GMT")) + 7200;
}
// end of DST (where applicable) (last Sunday in October 2 am local time)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 november {$year} GMT")) + 7200;
break;
case 16:
// Cuba
// start of DST (April 1st)
$dststart = strtotime("1 april {$year} GMT");
// end of DST (last Sunday in October)
$dstend = strtotime("-1 week sunday GMT", strtotime("1 november {$year} GMT"));
break;
case 17:
// Brazil
// start of DST (first Sunday in November)
$dststart = strtotime("1 week sunday GMT", strtotime("1 november {$year} GMT"));
// end of DST (third Sunday in February)
$dstend = strtotime("3 week sunday GMT", strtotime("1 february {$year} GMT"));
break;
case 18:
// Chile
// start of DST (Second Saturday of October - at midnight)
$dststart = strtotime("2 week saturday GMT", strtotime("1 october {$year} GMT"));
// end of DST (Second Saturday of March - at midnight)
$dstend = strtotime("2 week sunday GMT", strtotime("1 march {$year} GMT"));
break;
case 19:
// Falklands
// start of DST (First Sunday on or after 8 September)
$dststart = strtotime("next sunday GMT", strtotime("7 september {$year} GMT"));
// end of DST (First Sunday on or after 6 April)
$dstend = strtotime("next sunday GMT", strtotime("5 april {$year} GMT"));
break;
case 20:
// Paraguay
// start of DST (first Sunday in September)
$dststart = strtotime("1 week sunday GMT", strtotime("1 september {$year} GMT"));
// end of DST (first Sunday in April)
$dstend = strtotime("1 week sunday GMT", strtotime("1 april {$year} GMT"));
break;
}
// Have to use reverse logic in southern hemisphere.
$southern = array(
9,
10,
11,
12,
17,
18,
19,
20,
);
if (in_array($region, $southern)) {
return !($timestamp >= $dstart && $dstend <= $timestamp);
}
else {
return $dststart <= $timestamp && $timestamp <= $dstend;
}
}