You are here

function event_is_dst in Event 5.2

Same name and namespace in other branches
  1. 5 event_timezones.inc \event_is_dst()

Check if time is in Daylight Savings Time

Parameters

$dst_region the DST region as defined in event_timezones.inc:

$time a time string, format "YYYY-MM-DD HH:mm:ss" or date array:

Return value

0 or 1

Related topics

6 calls to event_is_dst()
event_check_dst in ./event.module
Get DST and TZ induced offset of event
event_cron in ./event.module
Implementation of hook_cron
event_dst in ./event.module
Display a page with the timezone and daylight savings time regions.
event_nodeapi in ./event.module
hook_nodeapi implementation
event_update_5 in ./event.install
Set DST

... See full list

File

./event.module, line 2458

Code

function event_is_dst($dst_region, $time) {
  if (is_string($time)) {
    $time = event_explode_date($time);
  }
  $year = $time['year'];
  $timestamp = strtotime($time['year'] . '-' . $time['month'] . '-' . $time['day'] . ' ' . $time['hour'] . ':' . $time['minute'] . ':' . $time['second']);

  // Information on Daylight Saving time was obtained from http://webexhibits.org/daylightsaving/g.html
  switch ($dst_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 (last Friday befor April 2nd, 2am)
      $dststart = strtotime("-1 week friday GMT", strtotime("2 april {$year} GMT"));

      // end of DST (Saturday between Rosh Hashana (Oct. 4-5) and Yom Kippur (Oct. 13))
      $dstend = strtotime("-1 saturday {$year} GMT", strtotime("13 october {$year} GMT"));
      switch ($year) {
        case '2007':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("16 september {$year} GMT"));
          break;
        case '2008':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("5 october {$year} GMT"));
          break;
        case '2009':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("27 september {$year} GMT"));
          break;
        case '2010':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("12 september {$year} GMT"));
          break;
        case '2011':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("2 october {$year} GMT"));
          break;
        case '2012':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("23 september {$year} GMT"));
          break;
        case '2013':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("8 september {$year} GMT"));
          break;
        case '2014':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("28 september {$year} GMT"));
          break;
        case '2015':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("20 september {$year} GMT"));
          break;
        case '2016':
          $dstend = strtotime("-1 saturday {$year} GMT", strtotime("9 october {$year} GMT"));
          break;
        default:

          // strictly speaking for 2005/6 only
          $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 (first Sunday in April)
      $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 (first Sunday in April)
      $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;
  }
  return (int) ($dststart <= $timestamp && $timestamp <= $dstend);
}