private static function getTimezoneData($timezone_identifier)
 {
     // I'm very shame of that code but now i cannot create something better due
     // php hasn't a smart API (even after they have
     // rewrote datetime functions).
     // Here we should find the offset  for the provided timezone and determine
     // whether the timezone has the DST offset ever.
     // We cannot use date("I") due it depends on current time (if the current time
     // is in winter, we 'll skip the zone)
     // so the best safe (but not fast) practice is to scan all tz transitions
     $timezone = new DateTimeZone($timezone_identifier);
     $current_date = new DateTime("now", $timezone);
     $current_ts = strtotime($current_date->format(DATE_W3C));
     $data = array("offset" => 0, "dst" => false);
     $transitions = $timezone->getTransitions();
     foreach ($transitions as &$transition) {
         $tt = new DateTime($transition['time'], $timezone);
         $ts = strtotime($tt->format(DATE_W3C));
         if ($ts < $current_ts) {
             continue;
         }
         if (!$transition['isdst']) {
             $transition = next($transitions);
         }
         $data['dst'] = $transition['isdst'];
         $data['offset'] = self::makeOffset($transition);
         break;
     }
     return $data;
 }
    function render_field($field)
    {
        /*
         *  Create a select dropdown with all available timezones
         */
        $utc = new DateTimeZone('UTC');
        $dt = new DateTime('now', $utc);
        ?>
        <select name="<?php 
        echo esc_attr($field['name']);
        ?>
">
            <?php 
        foreach (\DateTimeZone::listIdentifiers() as $tz) {
            $current_tz = new \DateTimeZone($tz);
            $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
            $abbr = $transition[0]['abbr'];
            $is_selected = trim($field['value']) === trim($tz) ? ' selected="selected"' : '';
            ?>
                <option value="<?php 
            echo $tz;
            ?>
"<?php 
            echo $is_selected;
            ?>
><?php 
            echo $tz . ' (' . $abbr . ')';
            ?>
</option>
            <?php 
        }
        ?>
        </select>
    <?php 
    }
 /**
  * Shows the general settings form.
  *
  * @param array $variables
  */
 public function actionGeneralSettings(array $variables = array())
 {
     if (empty($variables['info'])) {
         $variables['info'] = Craft::getInfo();
     }
     // Assemble the timezone options array
     // (Technique adapted from http://stackoverflow.com/a/7022536/1688568)
     $variables['timezoneOptions'] = array();
     $utc = new DateTime();
     $offsets = array();
     $timezoneIds = array();
     $includedAbbrs = array();
     foreach (\DateTimeZone::listIdentifiers() as $timezoneId) {
         $timezone = new \DateTimeZone($timezoneId);
         $transition = $timezone->getTransitions($utc->getTimestamp(), $utc->getTimestamp());
         $abbr = $transition[0]['abbr'];
         $offset = round($timezone->getOffset($utc) / 60);
         if ($offset) {
             $hour = floor($offset / 60);
             $minutes = floor(abs($offset) % 60);
             $format = sprintf('%+d', $hour);
             if ($minutes) {
                 $format .= ':' . sprintf('%02u', $minutes);
             }
         } else {
             $format = '';
         }
         $offsets[] = $offset;
         $timezoneIds[] = $timezoneId;
         $includedAbbrs[] = $abbr;
         $variables['timezoneOptions'][$timezoneId] = 'UTC' . $format . ($abbr != 'UTC' ? " ({$abbr})" : '') . ($timezoneId != 'UTC' ? ' - ' . $timezoneId : '');
     }
     array_multisort($offsets, $timezoneIds, $variables['timezoneOptions']);
     $this->renderTemplate('settings/general/index', $variables);
 }
Example #4
0
 /**
 		Return additional information for specified Unix timezone
 			@return array
 			@param $id string
 			@private
 	**/
 private static function tzdata($id)
 {
     $ref = new DateTimeZone($id);
     $loc = $ref->getLocation();
     $now = time();
     $trn = $ref->getTransitions($now, $now);
     return array('offset' => $ref->getOffset(new DateTime('now', new DateTimeZone('GMT'))) / 3600, 'country' => $loc['country_code'], 'latitude' => $loc['latitude'], 'longitude' => $loc['longitude'], 'dst' => $trn[0]['isdst']);
 }
Example #5
0
 /**
  *	Return information about specified Unix time zone
  *	@return array
  *	@param $zone string
  **/
 function tzinfo($zone)
 {
     $ref = new \DateTimeZone($zone);
     $loc = $ref->getLocation();
     $trn = $ref->getTransitions($now = time(), $now);
     $out = array('offset' => $ref->getOffset(new \DateTime('now', new \DateTimeZone('GMT'))) / 3600, 'country' => $loc['country_code'], 'latitude' => $loc['latitude'], 'longitude' => $loc['longitude'], 'dst' => $trn[0]['isdst']);
     unset($ref);
     return $out;
 }
Example #6
0
function timezoneDoesDST($tzId, $time = "")
{
    $tz = new DateTimeZone($tzId);
    $date = new DateTime($time != "" ? $time : "now", $tz);
    $trans = $tz->getTransitions();
    foreach ($trans as $k => $t) {
        if ($t["ts"] > $date->format('U')) {
            return $trans[$k - 1]['isdst'];
        }
    }
}
Example #7
0
 /**
  * Verifies that the given timezone exists and sets the timezone to the selected timezone
  *
  * @TODO Verify that the given timezone exists
  *
  * @param string $timezoneName
  * @return string
  */
 public function setTimezone($timeZoneName = 'UTC')
 {
     if (!$this->isValidTimeZone($timeZoneName)) {
         $timeZoneName = 'UTC';
     }
     $this->timezone = new \DateTimeZone($timeZoneName);
     $this->timezoneId = $this->timezone->getName();
     $transitions = $this->timezone->getTransitions();
     $this->timezoneInDST = $transitions[0]['isdst'];
     return $this->timezoneId;
 }
Example #8
0
 protected function timezoneExhibitsDST($tzId)
 {
     $tz = new \DateTimeZone($tzId);
     $date = new \DateTime("now", $tz);
     $trans = $tz->getTransitions();
     foreach ($trans as $k => $t) {
         if ($t["ts"] > $date->format('U')) {
             return $trans[$k - 1]['isdst'];
         }
     }
     return false;
 }
Example #9
0
 /**
  * Creates a new component.
  *
  * By default this object will iterate over its own children, but this can 
  * be overridden with the iterator argument
  * 
  * @param string $name 
  * @param Sabre\VObject\ElementList $iterator
  */
 public function __construct()
 {
     parent::__construct();
     $tz = new \DateTimeZone(\GO::user() ? \GO::user()->timezone : date_default_timezone_get());
     //$tz = new \DateTimeZone("Europe/Amsterdam");
     $transitions = $tz->getTransitions();
     $start_of_year = mktime(0, 0, 0, 1, 1);
     $to = \GO\Base\Util\Date::get_timezone_offset(time());
     if ($to < 0) {
         if (strlen($to) == 2) {
             $to = '-0' . $to * -1;
         }
     } else {
         if (strlen($to) == 1) {
             $to = '0' . $to;
         }
         $to = '+' . $to;
     }
     $STANDARD_TZOFFSETFROM = $STANDARD_TZOFFSETTO = $DAYLIGHT_TZOFFSETFROM = $DAYLIGHT_TZOFFSETTO = $to;
     $STANDARD_RRULE = '';
     $DAYLIGHT_RRULE = '';
     for ($i = 0, $max = count($transitions); $i < $max; $i++) {
         if ($transitions[$i]['ts'] > $start_of_year) {
             $weekday1 = $this->_getDay($transitions[$i]['time']);
             $weekday2 = $this->_getDay($transitions[$i + 1]['time']);
             if ($transitions[$i]['isdst']) {
                 $dst_start = $transitions[$i];
                 $dst_end = $transitions[$i + 1];
             } else {
                 $dst_end = $transitions[$i];
                 $dst_start = $transitions[$i + 1];
             }
             $STANDARD_TZOFFSETFROM = $this->_formatVtimezoneTransitionHour($dst_start['offset'] / 3600);
             $STANDARD_TZOFFSETTO = $this->_formatVtimezoneTransitionHour($dst_end['offset'] / 3600);
             $DAYLIGHT_TZOFFSETFROM = $this->_formatVtimezoneTransitionHour($dst_end['offset'] / 3600);
             $DAYLIGHT_TZOFFSETTO = $this->_formatVtimezoneTransitionHour($dst_start['offset'] / 3600);
             $DAYLIGHT_RRULE = "FREQ=YEARLY;BYDAY={$weekday1};BYMONTH=" . date('n', $dst_start['ts']);
             $STANDARD_RRULE = "FREQ=YEARLY;BYDAY={$weekday2};BYMONTH=" . date('n', $dst_end['ts']);
             break;
         }
     }
     $this->tzid = $tz->getName();
     //	$this->add("last-modified", "19870101T000000Z");
     $rrule = new \Sabre\VObject\Recur\RRuleIterator($STANDARD_RRULE, new \DateTime('1970-01-01 ' . substr($STANDARD_TZOFFSETFROM, 1) . ':00'));
     $rrule->next();
     $rrule->next();
     $this->add($this->createComponent("standard", array('dtstart' => $rrule->current()->format('Ymd\\THis'), 'rrule' => $STANDARD_RRULE, 'tzoffsetfrom' => $STANDARD_TZOFFSETFROM . "00", 'tzoffsetto' => $STANDARD_TZOFFSETTO . "00")));
     $rrule = new \Sabre\VObject\Recur\RRuleIterator($DAYLIGHT_RRULE, new \DateTime('1970-01-01 ' . substr($DAYLIGHT_TZOFFSETFROM, 1) . ':00'));
     $rrule->next();
     $rrule->next();
     $this->add($this->createComponent("daylight", array('dtstart' => $rrule->current()->format('Ymd\\THis'), 'rrule' => $DAYLIGHT_RRULE, 'tzoffsetfrom' => $DAYLIGHT_TZOFFSETFROM . "00", 'tzoffsetto' => $DAYLIGHT_TZOFFSETTO . "00")));
 }
Example #10
0
 public static function getInfo()
 {
     static $tz_info;
     if (!$tz_info) {
         $tz = Customization::get('timezone');
         $utc = new \DateTimeZone('UTC');
         $dt = new \DateTime('now', $utc);
         $current_tz = new \DateTimeZone($tz);
         $offset = $current_tz->getOffset($dt);
         $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
         $dt_in_tz = new \DateTime('now', $current_tz);
         $tz_info = array('code' => $tz, 'gmt_offset_seconds' => (double) $offset, 'gmt_offset_hours' => (double) ($offset / 3600), 'name' => $transition[0]['name'], 'abbr' => $transition[0]['abbr'], 'tz_object' => $current_tz, 'utc_object' => $utc, 'now_utc' => $dt, 'now' => $dt_in_tz);
     }
     return $tz_info;
 }
Example #11
0
 /** Returns an associative array with all the timezones as keys and a friendly description of each of them as values */
 public static function getTimezonesAsArray()
 {
     $utc = new \DateTimeZone('UTC');
     $dt = new \DateTime('now', $utc);
     $result = array();
     foreach (\DateTimeZone::listIdentifiers() as $tz) {
         $current_tz = new \DateTimeZone($tz);
         $offset = $current_tz->getOffset($dt);
         $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
         $abbr = $transition[0]['abbr'];
         $formatted = sprintf('%+03d:%02u', floor($offset / 3600), floor(abs($offset) % 3600 / 60));
         $result[$tz] = "{$tz} [ {$abbr} {$formatted} ]";
     }
     return $result;
 }
function day_of($time, $tzid=NULL) {
  $tztime = $time - ($time % 86400);
  if ($tzid !== NULL) {
    $timezone = new DateTimeZone($tzid);
    $transitions = $timezone->getTransitions();
    $is_dst = date('I', $tztime);
    $offset = 0;

    foreach ($transitions as $transition) {
      if ($transition['isdst'] == $is_dst) {
	$offset = $transition['offset'];
	break;
      }
    }

    $tztime = $tztime - $offset;
    if ($tztime > $time)
      $tztime -= 86400;
  }
  return $tztime;
}
Example #13
0
 private function vtimezone($icalEvents)
 {
     $params = JComponentHelper::getParams(JEV_COM_COMPONENT);
     $tzid = "";
     if (is_callable("date_default_timezone_set")) {
         $current_timezone = date_default_timezone_get();
         // Do the Timezone definition
         $tzid = ";TZID={$current_timezone}";
         // find the earliest start date
         $firststart = false;
         foreach ($icalEvents as $a) {
             if (!$firststart || $a->getUnixStartTime() < $firststart) {
                 $firststart = $a->getUnixStartTime();
             }
         }
         // Subtract 1 leap year to make sure we have enough transitions
         $firststart -= 31622400;
         $timezone = new DateTimeZone($current_timezone);
         if (version_compare(PHP_VERSION, "5.3.0") >= 0) {
             $transitions = $timezone->getTransitions($firststart);
         } else {
             $transitions = $timezone->getTransitions();
         }
         $tzindex = 0;
         while (JevDate::strtotime($transitions[$tzindex]['time']) < $firststart) {
             $tzindex++;
         }
         $transitions = array_slice($transitions, $tzindex);
         if (count($transitions) >= 2) {
             $lastyear = $params->get("com_latestyear", 2020);
             echo "BEGIN:VTIMEZONE\n";
             echo "TZID:{$current_timezone}\n";
             for ($t = 0; $t < count($transitions); $t++) {
                 $transition = $transitions[$t];
                 if ($transition['isdst'] == 0) {
                     if (JevDate::strftime("%Y", $transition['ts']) > $lastyear) {
                         continue;
                     }
                     echo "BEGIN:STANDARD\n";
                     echo "DTSTART:" . JevDate::strftime("%Y%m%dT%H%M%S\n", $transition['ts']);
                     if ($t < count($transitions) - 1) {
                         echo "RDATE:" . JevDate::strftime("%Y%m%dT%H%M%S\n", $transitions[$t + 1]['ts']);
                     }
                     // if its the first transition then assume the old setting is the same as the next otherwise use the previous value
                     $prev = $t;
                     $prev += $t == 0 ? 1 : -1;
                     $offset = $transitions[$prev]["offset"];
                     $sign = $offset >= 0 ? "+" : "-";
                     $offset = abs($offset);
                     $offset = $sign . sprintf("%04s", floor($offset / 3600) * 100 + $offset % 60);
                     echo "TZOFFSETFROM:{$offset}\n";
                     $offset = $transitions[$t]["offset"];
                     $sign = $offset >= 0 ? "" : "-";
                     $offset = abs($offset);
                     $offset = $sign . sprintf("%04s", floor($offset / 3600) * 100 + $offset % 60);
                     echo "TZOFFSETTO:{$offset}\n";
                     echo "TZNAME:{$current_timezone} " . $transitions[$t]["abbr"] . "\n";
                     echo "END:STANDARD\n";
                 }
             }
             for ($t = 0; $t < count($transitions); $t++) {
                 $transition = $transitions[$t];
                 if ($transition['isdst'] == 1) {
                     if (JevDate::strftime("%Y", $transition['ts']) > $lastyear) {
                         continue;
                     }
                     echo "BEGIN:DAYLIGHT\n";
                     echo "DTSTART:" . JevDate::strftime("%Y%m%dT%H%M%S\n", $transition['ts']);
                     if ($t < count($transitions) - 1) {
                         echo "RDATE:" . JevDate::strftime("%Y%m%dT%H%M%S\n", $transitions[$t + 1]['ts']);
                     }
                     // if its the first transition then assume the old setting is the same as the next otherwise use the previous value
                     $prev = $t;
                     $prev += $t == 0 ? 1 : -1;
                     $offset = $transitions[$prev]["offset"];
                     $sign = $offset >= 0 ? "+" : "-";
                     $offset = abs($offset);
                     $offset = $sign . sprintf("%04s", floor($offset / 3600) * 100 + $offset % 60);
                     echo "TZOFFSETFROM:{$offset}\n";
                     $offset = $transitions[$t]["offset"];
                     $sign = $offset >= 0 ? "" : "-";
                     $offset = abs($offset);
                     $offset = $sign . sprintf("%04s", floor($offset / 3600) * 100 + $offset % 60);
                     echo "TZOFFSETTO:{$offset}\n";
                     echo "TZNAME:{$current_timezone} " . $transitions[$t]["abbr"] . "\n";
                     echo "END:DAYLIGHT\n";
                 }
             }
             echo "END:VTIMEZONE\n";
         }
     }
     return $tzid;
 }
Example #14
0
    /**
     * Retrieve transitions for offsets of given timezone
     *
     * @param string $timezone
     * @param mixed $from
     * @param mixed $to
     * @return array
     * @SuppressWarnings(PHPMD.NPathComplexity)
     */
    protected function _getTZOffsetTransitions($timezone, $from = null, $to = null)
    {
        $tzTransitions = [];
        try {
            if (!empty($from)) {
                $from = $from instanceof \DateTime
                    ? $from->getTimestamp()
                    : (new \DateTime($from))->getTimestamp();
            }

            $to = $to instanceof \DateTime
                ? $to
                : new \DateTime($to);
            $nextPeriod = $this->getConnection()->formatDate(
                $to->format('Y-m-d H:i:s')
            );
            $to = $to->getTimestamp();

            $dtz = new \DateTimeZone($timezone);
            $transitions = $dtz->getTransitions();

            for ($i = count($transitions) - 1; $i >= 0; $i--) {
                $tr = $transitions[$i];
                try {
                    $this->timezoneValidator->validate($tr['ts'], $to);
                } catch (\Magento\Framework\Exception\ValidatorException $e) {
                    continue;
                }

                $tr['time'] = $this->getConnection()->formatDate(
                    (new \DateTime($tr['time']))->format('Y-m-d H:i:s')
                );
                $tzTransitions[$tr['offset']][] = ['from' => $tr['time'], 'to' => $nextPeriod];

                if (!empty($from) && $tr['ts'] < $from) {
                    break;
                }
                $nextPeriod = $tr['time'];
            }
        } catch (\Exception $e) {
            $this->_logger->critical($e);
        }

        return $tzTransitions;
    }
Example #15
0
var_dump(timezone_name_get($tz));
// Create two timezone objects, one for Taipei (Taiwan) and one for
// Tokyo (Japan)
$dateTimeZoneTaipei = timezone_open("Asia/Taipei");
$dateTimeZoneJapan = timezone_open("Asia/Tokyo");
// Create two DateTime objects that will contain the same Unix timestamp, but
// have different timezones attached to them.
$dateTimeTaipei = date_create("2008-08-08", $dateTimeZoneTaipei);
$dateTimeJapan = date_create("2008-08-08", $dateTimeZoneJapan);
var_dump(date_offset_get($dateTimeTaipei));
var_dump(date_offset_get($dateTimeJapan));
$tz = timezone_open("Asia/Shanghai");
var_dump(timezone_name_get($tz));
$timezone = timezone_open("CET");
$transitions = timezone_transitions_get($timezone);
var_dump($transitions[0]['ts']);
var_dump($transitions[0]['offset']);
var_dump($transitions[0]['isdst']);
var_dump($transitions[0]['abbr']);
$tz = timezone_open("EDT");
var_dump(timezone_name_get($tz));
$tz = timezone_open("PST");
var_dump(timezone_name_get($tz));
$tz = timezone_open("CHAST");
var_dump(timezone_name_get($tz));
var_dump((bool) timezone_version_get());
$timezone = new DateTimeZone("Europe/London");
$transitions = $timezone->getTransitions(1000000, 999999999);
var_dump($transitions[0]);
var_dump($transitions[3]);
var_dump($transitions[count($transitions) - 1]);
 /**
  * create timezone and standard/daylight components
  *
  * Result when 'Europe/Stockholm' and no from/to arguments is used as timezone:
  *
  * BEGIN:VTIMEZONE
  * TZID:Europe/Stockholm
  * BEGIN:STANDARD
  * DTSTART:20101031T020000
  * TZOFFSETFROM:+0200
  * TZOFFSETTO:+0100
  * TZNAME:CET
  * END:STANDARD
  * BEGIN:DAYLIGHT
  * DTSTART:20100328T030000
  * TZOFFSETFROM:+0100
  * TZOFFSETTO:+0200
  * TZNAME:CEST
  * END:DAYLIGHT
  * END:VTIMEZONE
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.11.8 - 2012-02-06
  * Generates components for all transitions in a date range, based on contribution by Yitzchok Lavi <*****@*****.**>
  * @param object $calendar, reference to an iCalcreator calendar instance
  * @param string $timezone, a PHP5 (DateTimeZone) valid timezone
  * @param array  $xProp,    *[x-propName => x-propValue], optional
  * @param int    $from      an unix timestamp
  * @param int    $to        an unix timestamp
  * @return bool
  */
 public static function createTimezone(&$calendar, $timezone, $xProp = array(), $from = null, $to = null)
 {
     if (!class_exists('DateTimeZone')) {
         return FALSE;
     }
     if (empty($timezone)) {
         return FALSE;
     }
     try {
         $dtz = new DateTimeZone($timezone);
         $transitions = $dtz->getTransitions();
         unset($dtz);
         $utcTz = new DateTimeZone('UTC');
     } catch (Exception $e) {
         return FALSE;
     }
     if (empty($to)) {
         $dates = array_keys($calendar->getProperty('dtstart'));
     }
     $transCnt = 2;
     // number of transitions in output if empty input $from/$to and an empty dates-array
     $dateFrom = new DateTime('now');
     $dateTo = new DateTime('now');
     if (!empty($from)) {
         $dateFrom->setTimestamp($from);
     } else {
         if (!empty($dates)) {
             $dateFrom = new DateTime(reset($dates));
         }
         // set lowest date to the lowest dtstart date
         $dateFrom->modify('-1 month');
         // set $dateFrom to one month before the lowest date
     }
     $dateFrom->setTimezone($utcTz);
     // convert local date to UTC
     if (!empty($to)) {
         $dateTo->setTimestamp($to);
     } else {
         if (!empty($dates)) {
             $dateTo = new DateTime(end($dates));
             // set highest date to the highest dtstart date
             $to = $dateTo->getTimestamp();
             // set mark that a highest date is found
         }
         $dateTo->modify('+1 year');
         // set $dateTo to one year after the highest date
     }
     $dateTo->setTimezone($utcTz);
     // convert local date to UTC
     $transTemp = array();
     $prevOffsetfrom = $stdCnt = $dlghtCnt = 0;
     $stdIx = $dlghtIx = null;
     $date = new DateTime('now', $utcTz);
     foreach ($transitions as $tix => $trans) {
         // all transitions in date-time order!!
         $date->setTimestamp($trans['ts']);
         // set transition date (UTC)
         if ($date < $dateFrom) {
             $prevOffsetfrom = $trans['offset'];
             // previous trans offset will be 'next' trans offsetFrom
             continue;
         }
         if ($date > $dateTo) {
             break;
         }
         // loop always (?) breaks here
         if (!empty($prevOffsetfrom) || 0 == $prevOffsetfrom) {
             $trans['offsetfrom'] = $prevOffsetfrom;
             // i.e. set previous offsetto as offsetFrom
             $date->modify($trans['offsetfrom'] . 'seconds');
             // convert utc date to local date
             $trans['time'] = array('year' => $date->format('Y'), 'month' => $date->format('n'), 'day' => $date->format('j'), 'hour' => $date->format('G'), 'min' => $date->format('i'), 'sec' => $date->format('s'));
         }
         $prevOffsetfrom = $trans['offset'];
         $trans['prevYear'] = $trans['time']['year'];
         if (TRUE !== $trans['isdst']) {
             // standard timezone
             if (!empty($stdIx) && isset($transTemp[$stdIx]['offsetfrom']) && $transTemp[$stdIx]['abbr'] == $trans['abbr'] && $transTemp[$stdIx]['offsetfrom'] == $trans['offsetfrom'] && $transTemp[$stdIx]['offset'] == $trans['offset'] && $transTemp[$stdIx]['prevYear'] + 1 == $trans['time']['year']) {
                 $transTemp[$stdIx]['prevYear'] = $trans['time']['year'];
                 $transTemp[$stdIx]['rdate'][] = $trans['time'];
                 continue;
             }
             $stdIx = $tix;
             $stdCnt += 1;
         } else {
             // daylight timezone
             if (!empty($dlghtIx) && isset($transTemp[$dlghtIx]['offsetfrom']) && $transTemp[$dlghtIx]['abbr'] == $trans['abbr'] && $transTemp[$dlghtIx]['offsetfrom'] == $trans['offsetfrom'] && $transTemp[$dlghtIx]['offset'] == $trans['offset'] && $transTemp[$dlghtIx]['prevYear'] + 1 == $trans['time']['year']) {
                 $transTemp[$dlghtIx]['prevYear'] = $trans['time']['year'];
                 $transTemp[$dlghtIx]['rdate'][] = $trans['time'];
                 continue;
             }
             $dlghtIx = $tix;
             $dlghtCnt += 1;
         }
         // end daylight timezone
         if (empty($to) && $transCnt == count($transTemp)) {
             // store only $transCnt transitions
             if (TRUE !== $transTemp[0]['isdst']) {
                 $stdCnt -= 1;
             } else {
                 $dlghtCnt -= 1;
             }
             array_shift($transTemp);
         }
         // end if( empty( $to ) && ( $transCnt == count( $transTemp )))
         $transTemp[$tix] = $trans;
     }
     // end foreach( $transitions as $tix => $trans )
     unset($transitions);
     if (empty($transTemp)) {
         return FALSE;
     }
     $tz =& $calendar->newComponent('vtimezone');
     $tz->setproperty('tzid', $timezone);
     if (!empty($xProp)) {
         foreach ($xProp as $xPropName => $xPropValue) {
             if ('x-' == strtolower(substr($xPropName, 0, 2))) {
                 $tz->setproperty($xPropName, $xPropValue);
             }
         }
     }
     foreach ($transTemp as $trans) {
         $type = TRUE !== $trans['isdst'] ? 'standard' : 'daylight';
         $scomp =& $tz->newComponent($type);
         $scomp->setProperty('dtstart', $trans['time']);
         //      $scomp->setProperty( 'x-utc-timestamp', $trans['ts'] );   // test ###
         if (!empty($trans['abbr'])) {
             $scomp->setProperty('tzname', $trans['abbr']);
         }
         $scomp->setProperty('tzoffsetfrom', iCalUtilityFunctions::offsetSec2His($trans['offsetfrom']));
         $scomp->setProperty('tzoffsetto', iCalUtilityFunctions::offsetSec2His($trans['offset']));
         if (isset($trans['rdate'])) {
             $scomp->setProperty('RDATE', $trans['rdate']);
         }
     }
     return TRUE;
 }
Example #17
0
 /**
  * create a calendar timezone and standard/daylight components
  *
  * Result when 'Europe/Stockholm' and no from/to arguments is used as timezone:
  *
  * BEGIN:VTIMEZONE
  * TZID:Europe/Stockholm
  * BEGIN:STANDARD
  * DTSTART:20101031T020000
  * TZOFFSETFROM:+0200
  * TZOFFSETTO:+0100
  * TZNAME:CET
  * END:STANDARD
  * BEGIN:DAYLIGHT
  * DTSTART:20100328T030000
  * TZOFFSETFROM:+0100
  * TZOFFSETTO:+0200
  * TZNAME:CEST
  * END:DAYLIGHT
  * END:VTIMEZONE
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.16.1 - 2012-11-26
  * Generates components for all transitions in a date range, based on contribution by Yitzchok Lavi <*****@*****.**>
  * Additional changes jpirkey
  * @param object $calendar, reference to an iCalcreator calendar instance
  * @param string $timezone, a PHP5 (DateTimeZone) valid timezone
  * @param array  $xProp,    *[x-propName => x-propValue], optional
  * @param int    $from      a unix timestamp
  * @param int    $to        a unix timestamp
  * @return bool
  */
 public static function createTimezone(&$calendar, $timezone, $xProp = array(), $from = null, $to = null)
 {
     if (empty($timezone)) {
         return FALSE;
     }
     if (!empty($from) && !is_int($from)) {
         return FALSE;
     }
     if (!empty($to) && !is_int($to)) {
         return FALSE;
     }
     try {
         $dtz = new DateTimeZone($timezone);
         $transitions = $dtz->getTransitions();
         $utcTz = new DateTimeZone('UTC');
     } catch (Exception $e) {
         return FALSE;
     }
     if (empty($to)) {
         $dates = array_keys($calendar->getProperty('dtstart'));
         if (empty($dates)) {
             $dates = array(date('Ymd'));
         }
     }
     if (!empty($from)) {
         $dateFrom = new DateTime("@{$from}");
     } else {
         $from = reset($dates);
         // set lowest date to the lowest dtstart date
         $dateFrom = new DateTime($from . 'T000000', $dtz);
         $dateFrom->modify('-1 month');
         // set $dateFrom to one month before the lowest date
         $dateFrom->setTimezone($utcTz);
         // convert local date to UTC
     }
     $dateFromYmd = $dateFrom->format('Y-m-d');
     if (!empty($to)) {
         $dateTo = new DateTime("@{$to}");
     } else {
         $to = end($dates);
         // set highest date to the highest dtstart date
         $dateTo = new DateTime($to . 'T235959', $dtz);
         $dateTo->modify('+1 year');
         // set $dateTo to one year after the highest date
         $dateTo->setTimezone($utcTz);
         // convert local date to UTC
     }
     $dateToYmd = $dateTo->format('Y-m-d');
     unset($dtz);
     $transTemp = array();
     $prevOffsetfrom = 0;
     $stdIx = $dlghtIx = null;
     $prevTrans = FALSE;
     foreach ($transitions as $tix => $trans) {
         // all transitions in date-time order!!
         $date = new DateTime("@{$trans['ts']}");
         // set transition date (UTC)
         $transDateYmd = $date->format('Y-m-d');
         if ($transDateYmd < $dateFromYmd) {
             $prevOffsetfrom = $trans['offset'];
             // previous trans offset will be 'next' trans offsetFrom
             $prevTrans = $trans;
             // save it in case we don't find any that match
             $prevTrans['offsetfrom'] = 0 < $tix ? $transitions[$tix - 1]['offset'] : 0;
             continue;
         }
         if ($transDateYmd > $dateToYmd) {
             break;
         }
         // loop always (?) breaks here
         if (!empty($prevOffsetfrom) || 0 == $prevOffsetfrom) {
             $trans['offsetfrom'] = $prevOffsetfrom;
             // i.e. set previous offsetto as offsetFrom
             $date->modify($trans['offsetfrom'] . 'seconds');
             // convert utc date to local date
             $d = $date->format('Y-n-j-G-i-s');
             // set date to array to ease up dtstart and (opt) rdate setting
             $d = explode('-', $d);
             $trans['time'] = array('year' => $d[0], 'month' => $d[1], 'day' => $d[2], 'hour' => $d[3], 'min' => $d[4], 'sec' => $d[5]);
         }
         $prevOffsetfrom = $trans['offset'];
         if (TRUE !== $trans['isdst']) {
             // standard timezone
             if (!empty($stdIx) && isset($transTemp[$stdIx]['offsetfrom']) && $transTemp[$stdIx]['abbr'] == $trans['abbr'] && $transTemp[$stdIx]['offsetfrom'] == $trans['offsetfrom'] && $transTemp[$stdIx]['offset'] == $trans['offset']) {
                 $transTemp[$stdIx]['rdate'][] = $trans['time'];
                 continue;
             }
             $stdIx = $tix;
         } else {
             // daylight timezone
             if (!empty($dlghtIx) && isset($transTemp[$dlghtIx]['offsetfrom']) && $transTemp[$dlghtIx]['abbr'] == $trans['abbr'] && $transTemp[$dlghtIx]['offsetfrom'] == $trans['offsetfrom'] && $transTemp[$dlghtIx]['offset'] == $trans['offset']) {
                 $transTemp[$dlghtIx]['rdate'][] = $trans['time'];
                 continue;
             }
             $dlghtIx = $tix;
         }
         // end daylight timezone
         $transTemp[$tix] = $trans;
     }
     // end foreach( $transitions as $tix => $trans )
     $tz =& $calendar->newComponent('vtimezone');
     $tz->setproperty('tzid', $timezone);
     if (!empty($xProp)) {
         foreach ($xProp as $xPropName => $xPropValue) {
             if ('x-' == strtolower(substr($xPropName, 0, 2))) {
                 $tz->setproperty($xPropName, $xPropValue);
             }
         }
     }
     if (empty($transTemp)) {
         // if no match found
         if ($prevTrans) {
             // then we use the last transition (before startdate) for the tz info
             $date = new DateTime("@{$prevTrans['ts']}");
             // set transition date (UTC)
             $date->modify($prevTrans['offsetfrom'] . 'seconds');
             // convert utc date to local date
             $d = $date->format('Y-n-j-G-i-s');
             // set date to array to ease up dtstart setting
             $d = explode('-', $d);
             $prevTrans['time'] = array('year' => $d[0], 'month' => $d[1], 'day' => $d[2], 'hour' => $d[3], 'min' => $d[4], 'sec' => $d[5]);
             $transTemp[0] = $prevTrans;
         } else {
             // or we use the timezone identifier to BUILD the standard tz info (?)
             $date = new DateTime('now', new DateTimeZone($timezone));
             $transTemp[0] = array('time' => $date->format('Y-m-d\\TH:i:s O'), 'offset' => $date->format('Z'), 'offsetfrom' => $date->format('Z'), 'isdst' => FALSE);
         }
     }
     unset($transitions, $date, $prevTrans);
     foreach ($transTemp as $tix => $trans) {
         $type = TRUE !== $trans['isdst'] ? 'standard' : 'daylight';
         $scomp =& $tz->newComponent($type);
         $scomp->setProperty('dtstart', $trans['time']);
         //      $scomp->setProperty( 'x-utc-timestamp', $tix.' : '.$trans['ts'] );   // test ###
         if (!empty($trans['abbr'])) {
             $scomp->setProperty('tzname', $trans['abbr']);
         }
         if (isset($trans['offsetfrom'])) {
             $scomp->setProperty('tzoffsetfrom', iCalUtilityFunctions::offsetSec2His($trans['offsetfrom']));
         }
         $scomp->setProperty('tzoffsetto', iCalUtilityFunctions::offsetSec2His($trans['offset']));
         if (isset($trans['rdate'])) {
             $scomp->setProperty('RDATE', $trans['rdate']);
         }
     }
     return TRUE;
 }
Example #18
0
 /**
  * @param  $name
  * @param  null    $selected
  * @param  array   $options
  * @return mixed
  */
 public function selectTimezone($name, $selected = null, $options = array())
 {
     $list = [];
     $utc = new \DateTimeZone('UTC');
     $dt = new \DateTime('now', $utc);
     foreach (\DateTimeZone::listIdentifiers() as $tz) {
         $current_tz = new \DateTimeZone($tz);
         $offset = $current_tz->getOffset($dt);
         $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
         $abbr = $transition[0]['abbr'];
         $list[$tz] = $tz . ' [' . $abbr . ' ' . $this->formatOffset($offset) . ']';
     }
     return $this->select($name, $list, $selected, $options);
 }
 /**
  * Returns the standard and daylight transitions for the given {@param $_timezone}
  * and {@param $_year}.
  * 
  * @param DateTimeZone $_timezone
  * @param $_year
  * @return Array
  */
 protected function _getTransitionsForTimezoneAndYear(DateTimeZone $_timezone, $_year)
 {
     $standardTransition = null;
     $daylightTransition = null;
     if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
         // Since php version 5.3.0 getTransitions accepts optional start and end parameters.
         $start = mktime(0, 0, 0, 12, 1, $_year - 1);
         $end = mktime(24, 0, 0, 12, 31, $_year);
         $transitions = $_timezone->getTransitions($start, $end);
     } else {
         $transitions = $_timezone->getTransitions();
     }
     $index = 0;
     //we need to access index counter outside of the foreach loop
     $transition = array();
     //we need to access the transition counter outside of the foreach loop
     foreach ($transitions as $index => $transition) {
         if (strftime('%Y', $transition['ts']) == $_year) {
             if (isset($transitions[$index + 1]) && strftime('%Y', $transitions[$index]['ts']) == strftime('%Y', $transitions[$index + 1]['ts'])) {
                 $daylightTransition = $transition['isdst'] ? $transition : $transitions[$index + 1];
                 $standardTransition = $transition['isdst'] ? $transitions[$index + 1] : $transition;
             } else {
                 $daylightTransition = $transition['isdst'] ? $transition : null;
                 $standardTransition = $transition['isdst'] ? null : $transition;
             }
             break;
         } elseif ($index == count($transitions) - 1) {
             $standardTransition = $transition;
         }
     }
     return array($standardTransition, $daylightTransition);
 }
 /**
  *    Return the Timezone transition for the specified timezone and timestamp
  *
  * @param        DateTimeZone $objTimezone The timezone for finding the transitions
  * @param        integer      $timestamp   PHP date/time value for finding the current transition
  *
  * @return        array                The current transition details
  */
 private static function _getTimezoneTransitions($objTimezone, $timestamp)
 {
     $allTransitions = $objTimezone->getTransitions();
     $transitions = array();
     foreach ($allTransitions as $key => $transition) {
         if ($transition['ts'] > $timestamp) {
             $transitions[] = $key > 0 ? $allTransitions[$key - 1] : $transition;
             break;
         }
         if (empty($transitions)) {
             $transitions[] = end($allTransitions);
         }
     }
     return $transitions;
 }
Example #21
0
/**
 * Get a string representing the timespan of an event
 *
 * @param object $event
 * @return string
 */
function eventbrite_venue_get_event_date_timespan($event, $occurrence = 0)
{
    if (!is_object($event)) {
        return new WP_Error('event_not_set', esc_html__("The event variable is expected to be an object."));
    }
    try {
        $tz = new DateTimeZone($event->start->timezone);
    } catch (Exception $e) {
        return new WP_Error('bad_datetimezone', $e->getMessage());
    }
    $event_start_date = $event->start->local;
    $event_end_date = $event->end->local;
    try {
        $start_date = new DateTime($event_start_date, $tz);
    } catch (Exception $e) {
        return new WP_Error('bad_datetime', $e->getMessage());
    }
    try {
        $end_date = new DateTime($event_end_date, $tz);
    } catch (Exception $e) {
        return new WP_Error('bad_datetime', $e->getMessage());
    }
    if ($start_date->format('mdY') === $end_date->format('mdY')) {
        $date_format_start = 'l, F j, Y \\f\\r\\o\\m g:i A';
        $date_format_end = '\\t\\o g:i A';
    } else {
        $date_format_start = 'l, F j, Y \\a\\t g:i A';
        $date_format_end = '- l, F j, Y \\a\\t g:i A';
    }
    $time_zone_transitions = $tz->getTransitions();
    $time_zone_string = $time_zone_transitions[0]['abbr'];
    return sprintf(_x('%s %s (%s)', 'event timespan: statdate, end date, (time zone)', 'eventbrite-venue'), $start_date->format($date_format_start), $end_date->format($date_format_end), $time_zone_string);
}
<?php

/* Prototype  : array DateTimeZone::getTransitions  ()
 * Description: Returns all transitions for the timezone
 * Source code: ext/date/php_date.c
 * Alias to functions: timezone_transitions_get()
 */
echo "*** Testing DateTimeZone::getTransitions() : basic functionality ***\n";
//Set the default time zone
date_default_timezone_set("Europe/London");
// Create a DateTimeZone object
$tz = new DateTimeZone("Europe/London");
$tran = $tz->getTransitions(-306972000, -37241999);
if (!is_array($tran)) {
    echo "TEST FAILED: Expected an array\n";
}
echo "\n-- Total number of transitions: " . count($tran) . " --\n";
echo "\n-- Format a sample entry for Spring 1963 --\n";
var_dump($tran[6]);
?>
===DONE===
Example #23
0
function getTime()
{
    //return strtotime("now America/Toronto");
    $theTime = time();
    // specific date/time we're checking, in epoch seconds.
    $tz = new DateTimeZone('America/Toronto');
    $transition = $tz->getTransitions($theTime, $theTime);
    // only one array should be returned into $transition. Now get the data:
    $offset = $transition[0]['offset'];
    $current_time = time();
    $current_tz = new DateTimeZone('America/Los_Angeles');
    $trans = $current_tz->getTransitions($current_time, $current_time);
    //$offset_origin = $trans[0]['offset'];
    return $theTime - $offset - 3600;
}
 public function timezoneDoesDST($tzId)
 {
     $tz = new DateTimeZone($tzId);
     $trans = $tz->getTransitions();
     return count($trans) && $trans[count($trans) - 1]['ts'] > time();
 }
Example #25
0
 /**
  * Generate ActiveSync Timezone Packed String.
  * @param string $timezone
  * @param string $with_names
  * @throws Exception
  */
 private function _GetTimezoneString($timezone, $with_names = true)
 {
     // UTC needs special handling
     if ($timezone == "UTC") {
         return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0));
     }
     try {
         //Generate a timezone string (PHP 5.3 needed for this)
         $timezone = new DateTimeZone($timezone);
         $trans = $timezone->getTransitions(time());
         $stdTime = null;
         $dstTime = null;
         if (count($trans) < 3) {
             throw new Exception();
         }
         if ($trans[1]['isdst'] == 1) {
             $dstTime = $trans[1];
             $stdTime = $trans[2];
         } else {
             $dstTime = $trans[2];
             $stdTime = $trans[1];
         }
         $stdTimeO = new DateTime($stdTime['time']);
         $stdFirst = new DateTime(sprintf("first sun of %s %s", $stdTimeO->format('F'), $stdTimeO->format('Y')), timezone_open("UTC"));
         $stdBias = $stdTime['offset'] / -60;
         $stdName = $stdTime['abbr'];
         $stdYear = 0;
         $stdMonth = $stdTimeO->format('n');
         $stdWeek = floor(($stdTimeO->format("j") - $stdFirst->format("j")) / 7) + 1;
         $stdDay = $stdTimeO->format('w');
         $stdHour = $stdTimeO->format('H');
         $stdMinute = $stdTimeO->format('i');
         $stdTimeO->add(new DateInterval('P7D'));
         if ($stdTimeO->format('n') != $stdMonth) {
             $stdWeek = 5;
         }
         $dstTimeO = new DateTime($dstTime['time']);
         $dstFirst = new DateTime(sprintf("first sun of %s %s", $dstTimeO->format('F'), $dstTimeO->format('Y')), timezone_open("UTC"));
         $dstName = $dstTime['abbr'];
         $dstYear = 0;
         $dstMonth = $dstTimeO->format('n');
         $dstWeek = floor(($dstTimeO->format("j") - $dstFirst->format("j")) / 7) + 1;
         $dstDay = $dstTimeO->format('w');
         $dstHour = $dstTimeO->format('H');
         $dstMinute = $dstTimeO->format('i');
         $dstTimeO->add(new DateInterval('P7D'));
         if ($dstTimeO->format('n') != $dstMonth) {
             $dstWeek = 5;
         }
         $dstBias = ($dstTime['offset'] - $stdTime['offset']) / -60;
         if ($with_names) {
             return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', $stdBias, $stdName, 0, $stdMonth, $stdDay, $stdWeek, $stdHour, $stdMinute, 0, 0, 0, $dstName, 0, $dstMonth, $dstDay, $dstWeek, $dstHour, $dstMinute, 0, 0, $dstBias));
         } else {
             return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', $stdBias, '', 0, $stdMonth, $stdDay, $stdWeek, $stdHour, $stdMinute, 0, 0, 0, '', 0, $dstMonth, $dstDay, $dstWeek, $dstHour, $dstMinute, 0, 0, $dstBias));
         }
     } catch (Exception $e) {
         // If invalid timezone is given, we return UTC
         return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0));
     }
     return base64_encode(pack('la64vvvvvvvvla64vvvvvvvvl', 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0));
 }
Example #26
0
 /**
  *    Return the Timezone offset used for date/time conversions to/from UST
  *    This requires both the timezone and the calculated date/time to allow for local DST
  *
  *    @param    string             $timezone         The timezone for finding the adjustment to UST
  *    @param    integer            $timestamp        PHP date/time value
  *    @return   integer            Number of seconds for timezone adjustment
  *    @throws   \PHPExcel\Exception
  */
 public static function getTimeZoneAdjustment($timezone, $timestamp)
 {
     if ($timezone !== null) {
         if (!self::validateTimezone($timezone)) {
             throw new \PHPExcel\Exception("Invalid timezone " . $timezone);
         }
     } else {
         $timezone = self::$timezone;
     }
     if ($timezone == 'UST') {
         return 0;
     }
     $objTimezone = new \DateTimeZone($timezone);
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $transitions = $objTimezone->getTransitions($timestamp, $timestamp);
     } else {
         $transitions = self::getTimezoneTransitions($objTimezone, $timestamp);
     }
     return count($transitions) > 0 ? $transitions[0]['offset'] : 0;
 }
Example #27
0
 /**
  * Get the transition data for moving from DST to STD time.
  *
  * @param DateTimeZone $timezone  The timezone to get the transition for
  * @param Horde_Date $date        The date to start from. Really only the
  *                                year we are interested in is needed.
  *
  * @return array  An array containing the the STD and DST transitions
  */
 protected static function _getTransitions(DateTimeZone $timezone, Horde_Date $date)
 {
     $std = $dst = array();
     $transitions = $timezone->getTransitions(mktime(0, 0, 0, 12, 1, $date->year - 1), mktime(24, 0, 0, 12, 31, $date->year));
     if ($transitions === false) {
         return array();
     }
     foreach ($transitions as $i => $transition) {
         try {
             $d = new Horde_Date($transition['time']);
             $d->setTimezone('UTC');
         } catch (Exception $e) {
             continue;
         }
         if ($d->format('Y') == $date->format('Y') && isset($transitions[$i + 1])) {
             $next = new Horde_Date($transitions[$i + 1]['ts']);
             if ($d->format('Y') == $next->format('Y')) {
                 $dst = $transition['isdst'] ? $transition : $transitions[$i + 1];
                 $std = $transition['isdst'] ? $transitions[$i + 1] : $transition;
             } else {
                 $dst = $transition['isdst'] ? $transition : null;
                 $std = $transition['isdst'] ? null : $transition;
             }
             break;
         } elseif ($i == count($transitions) - 1) {
             $std = $transition;
         }
     }
     return array($std, $dst);
 }
Example #28
0
X-ORIGINAL-URL:<?php 
echo JRoute::_('index.php', true, -1);
?>

X-WR-CALDESC:<?php 
echo $config['sitename'];
?>
 RaidPlanner
<?php 
if (class_exists('DateTimeZone')) {
    ?>
BEGIN:VTIMEZONE
TZID:UTC
<?php 
    $timezone = new DateTimeZone('UTC');
    $transitions = $timezone->getTransitions();
    foreach ($transitions as $tridx => $transition) {
        if ($tridx > 0) {
            ?>

BEGIN:<?php 
            echo $transition['isdst'] == 1 ? 'DAYLIGHT' : 'STANDARD';
            ?>

TZOFFSETFROM:<?php 
            printf('%+05d', $transitions[$tridx - 1]['offset'] / 36);
            ?>

RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
DTSTART:<?php 
            echo str_replace(array('-', ':'), '', substr($transition['time'], 0, -5));
Example #29
0
					<div class="input-field col s12">
						<input id="community_name" name="community_name" type="text" class="validate">
						<label for="community_name">Community name</label>
					</div>
				</div>
				
				<div class="row">
					<div class="input-field col s12">
						<input id="community_url" name="community_url" type="text" class="validate" value="', getURL(), '">
						<label for="community_url">Community url</label>
					</div>
				</div>
				
				<div class="input-field col s12 m6">
					<select name="community_timezone" id="db_type">';
foreach (DateTimeZone::listIdentifiers() as $tz) {
    $current_tz = new DateTimeZone($tz);
    $offset = $current_tz->getOffset($dt);
    $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
    $abbr = $transition[0]['abbr'];
    echo '<option value="' . $tz . '">' . $tz . ' [' . $abbr . ' ' . Installation::formatOffset($offset) . ']</option>';
}
echo '</select>
					<label>Database type</label>
				</div>
				
				<input type="submit" class="btn-flat waves-effect waves-greyBlue waves-light right" value="Next">
			</form>
		</div>
	</div>
</div>';
    /**
     * Creates users and puts them in the right groups.
     * Also populates the users array.
     */
    private function save_users()
    {
        global $db, $config, $settings;
        // Hash the password.
        if (defined('PHPBB_31')) {
            global $passwords_manager;
            $password = $passwords_manager->hash('123456');
        } else {
            $password = phpbb_hash('123456');
        }
        $registered_group = $newly_registered_group = 0;
        // Get the group id for registered users and newly registered.
        $sql = 'SELECT group_id, group_name FROM ' . GROUPS_TABLE . '
			WHERE group_name = \'REGISTERED\'
			OR group_name = \'NEWLY_REGISTERED\'';
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if ($row['group_name'] == 'REGISTERED') {
                $registered_group = (int) $row['group_id'];
            } else {
                $newly_registered_group = (int) $row['group_id'];
            }
        }
        $db->sql_freeresult($result);
        $s_chunks = $this->num_users > $this->user_chunks ? true : false;
        $end = $this->num_users + 1;
        $chunk_cnt = 0;
        $sql_ary = array();
        if (!defined('PHPBB_31')) {
            $tz = new DateTimeZone($settings->get_config('qi_tz', ''));
            $tz_ary = $tz->getTransitions(time());
            $offset = (double) $tz_ary[0]['offset'] / 3600;
            // 3600 seconds = 1 hour.
            $qi_dst = $tz_ary[0]['isdst'] ? 1 : 0;
            unset($tz_ary, $tz);
        }
        foreach ($this->user_arr as $user) {
            $email = $user['username_clean'] . $this->email_domain;
            $sql_ary[] = array('user_id' => $user['user_id'], 'username' => $user['username'], 'username_clean' => $user['username_clean'], 'user_lastpost_time' => $user['user_lastpost_time'], 'user_lastmark' => $user['user_lastmark'], 'user_posts' => $user['user_posts'], 'user_password' => $password, 'user_email' => $email, 'user_email_hash' => phpbb_email_hash($email), 'group_id' => $registered_group, 'user_type' => USER_NORMAL, 'user_permissions' => '', 'user_lang' => $settings->get_config('qi_lang'), 'user_form_salt' => unique_id(), 'user_style' => (int) $config['default_style'], 'user_regdate' => $user['user_regdate'], 'user_passchg' => $user['user_passchg'], 'user_options' => 230271, 'user_full_folder' => PRIVMSGS_NO_BOX, 'user_notify_type' => NOTIFY_EMAIL, 'user_dateformat' => 'M jS, ’y, H:i', 'user_sig' => '');
            $count = count($sql_ary) - 1;
            if (defined('PHPBB_31')) {
                $sql_ary[$count]['user_timezone'] = $settings->get_config('qi_tz', '');
            } else {
                $sql_ary[$count]['user_timezone'] = $offset;
                $sql_ary[$count]['user_pass_convert'] = 0;
                $sql_ary[$count]['user_occ'] = '';
                $sql_ary[$count]['user_interests'] = '';
                $sql_ary[$count]['user_dst'] = $qi_dst;
            }
            $chunk_cnt++;
            if ($s_chunks && $chunk_cnt >= $this->user_chunks) {
                // throw the array to the users table
                $db->sql_multi_insert(USERS_TABLE, $sql_ary);
                unset($sql_ary);
                $sql_ary = array();
                $chunk_cnt = 0;
            }
        }
        // If there are any remaining users we need to throw them in to.
        if (!empty($sql_ary)) {
            $db->sql_multi_insert(USERS_TABLE, $sql_ary);
        }
        unset($sql_ary);
        // Put them in groups.
        $chunk_cnt = $newly_registered = $skip = 0;
        // Don't add the first users to the newly registered group if a moderator and/or an admin is needed.
        $skip = $this->create_mod ? $skip + 1 : $skip;
        $skip = $this->create_admin ? $skip + 1 : $skip;
        // First the registered group.
        foreach ($this->user_arr as $user) {
            $sql_ary[] = array('user_id' => (int) $user['user_id'], 'group_id' => (int) $registered_group, 'group_leader' => 0, 'user_pending' => 0);
            if ($newly_registered < $this->num_new_group && $skip < 1) {
                $sql_ary[] = array('user_id' => (int) $user['user_id'], 'group_id' => (int) $newly_registered_group, 'group_leader' => 0, 'user_pending' => 0);
                $newly_registered++;
            }
            $skip--;
            if ($s_chunks && $chunk_cnt >= $this->user_chunks) {
                // throw the array to the users table
                $db->sql_multi_insert(USER_GROUP_TABLE, $sql_ary);
                unset($sql_ary);
                $sql_ary = array();
                $chunk_cnt = 0;
            }
        }
        $db->sql_multi_insert(USER_GROUP_TABLE, $sql_ary);
        // Get the last user
        $user = end($this->user_arr);
        set_config('newest_user_id', $user['user_id']);
        set_config('newest_username', $user['username']);
        set_config('newest_user_colour', '');
        // phpBB installs the forum with one user.
        set_config('num_users', $this->num_users + 1);
    }