You are here

function date_is_dst in Date 6

Same name and namespace in other branches
  1. 5.2 date_php4/date_php4.inc \date_is_dst()
  2. 5 date_timezones.inc \date_is_dst()
  3. 6.2 date_php4/date_php4.inc \date_is_dst()

Check if time is in Daylight Savings Time

Parameters

$region: A dst region code, as stored in the $timezone_map array from date_php4_tz_map.inc

$timestamp: A GMT timestamp

Return value

0 or 1

1 call to date_is_dst()
date_php4.inc in date_php4/date_php4.inc

File

date_php4/date_php4.inc, line 610

Code

function date_is_dst($region, $timestamp) {
  if ($timestamp < 86400) {

    //return FALSE;
  }
  $year = date_gmdate('Y', $timestamp);

  // 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 UTC", strtotime("1 may {$year} UTC"));

      // end of DST (last Thursday in September)
      $dstend = strtotime("-1 week thursday UTC", strtotime("1 october {$year} UTC"));
      break;
    case 2:

      // Namibia
      // start of DST (first Sunday in September)
      $dststart = strtotime("1 week sunday UTC", strtotime("1 september {$year} UTC"));

      // end of DST (first Sunday April)
      $dstend = strtotime("1 week sunday UTC", strtotime("1 april {$year} UTC"));
      break;
    case 3:

      // Former USSR
      // start of DST (last Sunday in March)
      $dststart = strtotime("-1 week sunday UTC", strtotime("1 april {$year} UTC"));

      // end of DST (last Sunday October)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 november {$year} UTC"));
      break;
    case 4:

      // Iraq, Syria
      // start of DST (April 1st)
      $dststart = strtotime("1 april {$year} UTC");

      // end of DST (October 1st)
      $dstend = strtotime("1 october {$year} UTC");
      break;
    case 5:

      // Israel
      // start of DST (April 1st)
      $dststart = strtotime("1 april {$year} UTC");

      // 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} UTC", strtotime("13 october {$year} UTC"));
      break;
    case 6:

      // Lebanon, Kirgizstan
      // start of DST (Last Sunday in March)
      $dststart = strtotime("-1 week sunday UTC", strtotime("1 april {$year} UTC"));

      // end of DST (Last Sunday in October)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 november {$year} UTC"));
      break;
    case 7:

      // Palestine
      // start of DST (First Friday on or after April 15th)
      $dststart = strtotime("next friday UTC", strtotime("14 april {$year} UTC"));

      // end of DST (First Friday on or after October 15th)
      $dstend = strtotime("next friday UTC", strtotime("14 october {$year} UTC"));
      break;
    case 8:

      // Iran
      // start of DST (the first day of Farvardin (March 21))
      $dststart = strtotime("21 march {$year} UTC");

      // end of DST (the first day of Mehr (September 23))
      $dstend = strtotime("23 september {$year} UTC");
      break;
    case 9:

      // South Australia
      // start of DST  (last Sunday in October)
      $dststart = strtotime("-1 week sunday UTC", strtotime("1 november {$year} UTC"));

      // end of DST (last Sunday in March)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 april {$year} UTC"));
      break;
    case 10:

      // Australia, Tasmania
      // start of DST  (first Sunday in October)
      $dststart = strtotime("1 week sunday UTC", strtotime("1 october {$year} UTC"));

      // end of DST (last Sunday in March)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 april {$year} UTC"));
      break;
    case 11:

      // New Zealand
      // start of DST  (first Sunday in October)
      $dststart = strtotime("1 week sunday UTC", strtotime("1 october {$year} UTC"));

      // end of DST (third Sunday in March)
      $dstend = strtotime("3 week sunday UTC", strtotime("1 march {$year} UTC"));
      break;
    case 12:

      // Tonga
      // start of DST (first Sunday in November)
      $dststart = strtotime("1 week sunday UTC", strtotime("1 november {$year} UTC"));

      // end of DST (last Sunday in January)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 february {$year} UTC"));
      break;
    case 13:

      // EU and other European countries
      // start of DST (last Sunday in March 1 am UTC)
      $dststart = strtotime("-1 week sunday UTC", strtotime("1 april {$year} UTC")) + 3600;

      // end of DST in Europe (last Sunday in October 1 am UTC)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 november {$year} UTC")) + 3600;
      break;
    case 14:

      // Russian Federation
      // start of DST (last Sunday in March 2 am local time)
      $dststart = strtotime("-1 week sunday UTC", strtotime("1 april {$year} UTC")) + 7200;

      // end of DST (last Sunday in October 2 am local time)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 november {$year} UTC")) + 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)
      if ($year < 2007) {
        $dststart = strtotime("1 week sunday UTC", strtotime("1 april {$year} UTC")) + 7200;
      }
      else {
        $dststart = strtotime("1 week sunday UTC", strtotime("1 march {$year} UTC")) + 7200;
      }

      // end of DST (where applicable) (last Sunday in October 2 am local time)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 november {$year} UTC")) + 7200;
      break;
    case 16:

      // Cuba
      // start of DST  (April 1st)
      $dststart = strtotime("1 april {$year} UTC");

      // end of DST (last Sunday in October)
      $dstend = strtotime("-1 week sunday UTC", strtotime("1 november {$year} UTC"));
      break;
    case 17:

      // Brazil
      // start of DST  (first Sunday in November)
      $dststart = strtotime("1 week sunday UTC", strtotime("1 november {$year} UTC"));

      // end of DST (third Sunday in February)
      $dstend = strtotime("3 week sunday UTC", strtotime("1 february {$year} UTC"));
      break;
    case 18:

      // Chile
      // start of DST  (Second Saturday of October - at midnight)
      $dststart = strtotime("2 week saturday UTC", strtotime("1 october {$year} UTC"));

      // end of DST (Second Saturday of March - at midnight)
      $dstend = strtotime("2 week sunday UTC", strtotime("1 march {$year} UTC"));
      break;
    case 19:

      // Falklands
      // start of DST  (First Sunday on or after 8 September)
      $dststart = strtotime("next sunday UTC", strtotime("7 september {$year} UTC"));

      // end of DST (First Sunday on or after 6 April)
      $dstend = strtotime("next sunday UTC", strtotime("5 april {$year} UTC"));
      break;
    case 20:

      // Paraguay
      // start of DST  (first Sunday in September)
      $dststart = strtotime("1 week sunday UTC", strtotime("1 september {$year} UTC"));

      // end of DST (first Sunday in April)
      $dstend = strtotime("1 week sunday UTC", strtotime("1 april {$year} UTC"));
      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;
  }
}