You are here

function event_cron in Event 5.2

Implementation of hook_cron

File

./event.module, line 2289

Code

function event_cron() {

  // 1) Check all DST regions for a recent change in DST
  $time = _event_user_time();
  $time_old = event_date_later($time, -1);
  $changed_regions = array();
  for ($i = 1; $i <= 20; $i++) {
    $before = event_is_dst($i, $time_old);
    $now = event_is_dst($i, $time);
    if ($before != $now) {
      $changed_regions[$i] = array(
        $before,
        $now,
      );
    }
  }
  $site_timezone = variable_get('date_default_timezone_id', 0);

  // 2) Change user tz offset
  foreach ($changed_regions as $key => $values) {
    $result = db_query('SELECT * FROM {event_timezones} WHERE dst_region = %d', $key);
    if ($values[1] == 1) {
      db_query('UPDATE {event_timezones} SET is_dst = 1 WHERE dst_region = %d', $key);
    }
    else {
      db_query('UPDATE {event_timezones} SET is_dst = 0 WHERE dst_region = %d', $key);
    }
    while ($zone = db_fetch_object($result)) {
      if ($values[1] == 1) {
        $offset = explode(':', $zone->offset_dst);
      }
      else {
        $offset = explode(':', $zone->offset);
      }
      $offset = $offset[0] * 3600 + $offset[1] * 60 + $offset[2];
      db_query('UPDATE {users} SET timezone = %d WHERE timezone_id = %d', $offset, $zone->timezone);
      if ($site_timezone == $zone->timezone) {
        variable_set('date_default_timezone', $offset);
      }
    }
  }
}