示例#1
0
 public function __construct()
 {
     global $wpdb;
     if (get_option('timezone_string')) {
         $this->tz_offset = timezone_offset_get(timezone_open(get_option('timezone_string')), new DateTime());
     } else {
         if (get_option('gmt_offset')) {
             $this->tz_offset = get_option('gmt_offset') * 60 * 60;
         }
     }
     $this->db = $wpdb;
     $this->tb_prefix = $wpdb->prefix;
     $this->agent = $this->get_UserAgent();
     $this->historical = array();
     // Load the options from the database
     $this->options = get_option('wp_statistics');
     // Set the default co-efficient.
     $this->coefficient = $this->get_option('coefficient', 1);
     // Double check the co-efficient setting to make sure it's not been set to 0.
     if ($this->coefficient <= 0) {
         $this->coefficient = 1;
     }
     // This is a bit of a hack, we strip off the "includes/classes" at the end of the current class file's path.
     $this->plugin_dir = substr(dirname(__FILE__), 0, -17);
     $this->plugin_url = substr(plugin_dir_url(__FILE__), 0, -17);
     $this->get_IP();
     if ($this->get_option('hash_ips') == true) {
         $this->ip_hash = '#hash#' . sha1($this->ip + $_SERVER['HTTP_USER_AGENT']);
     }
 }
 /**
  * @return array order data in API form
  * @throws PilipayError
  */
 public function toApiArray()
 {
     // check goods list
     if (empty($this->_goodsList)) {
         throw new PilipayError(PilipayError::REQUIRED_ARGUMENT_NO_EXIST, array('name' => 'goodsList', 'value' => Tools::jsonEncode($this->_goodsList)));
     }
     // if the orderTime is omitted, use current time
     if (empty($this->orderTime)) {
         $now = date_create('now', timezone_open('Asia/Shanghai'))->format('Y-m-d H:i:s');
         $this->orderTime = $this->orderTime ? $this->orderTime : $now;
     }
     // verify
     parent::verifyFields();
     $apiArray = array_map('strval', array('version' => $this->version, 'merchantNo' => $this->merchantNo, 'currencyType' => $this->currencyType, 'orderNo' => $this->orderNo, 'orderAmount' => (int) round($this->orderAmount * 100), 'orderTime' => $this->orderTime, 'pageUrl' => $this->pageUrl, 'serverUrl' => $this->serverUrl, 'redirectUrl' => $this->redirectUrl, 'notifyType' => $this->notifyType, 'shipper' => (int) round($this->shipper * 100), 'tax' => (int) round($this->tax * 100), 'signType' => $this->signType));
     // sign
     if ($this->signType == 'MD5') {
         // sign using MD5
         $this->signMsg = md5(implode('', $apiArray) . $this->appSecret);
         $apiArray['signMsg'] = $this->signMsg;
     } else {
         throw new PilipayError(PilipayError::INVALID_ARGUMENT, array('name' => 'signType', 'value' => $this->signType));
     }
     $apiArray['goodsList'] = urlencode(Tools::jsonEncode($this->_goodsList));
     return $apiArray;
 }
function print_comment_item($tag, $id, $author, $date, $comment)
{
    global $domain;
    $output = "";
    $output .= "  <item>\n";
    $output .= "    <title>#";
    $output .= $id;
    $output .= " on tag ";
    $output .= $tag;
    $output .= " by ";
    $output .= htmlentities($author);
    $output .= "</title>\n";
    $output .= "    <link>";
    $output .= $domain . href('tag/' . $tag . '#comment-' . $id);
    $output .= "</link>\n";
    $output .= "    <description>A new comment by ";
    $output .= $author;
    $output .= " on tag ";
    $output .= $tag;
    $output .= ".";
    $output .= "</description>\n";
    $output .= "    <content:encoded><![CDATA[";
    $output .= Markdown(htmlspecialchars($comment));
    $output .= "]]></content:encoded>\n";
    $output .= "    <dc:creator>";
    $output .= $author;
    $output .= "</dc:creator>\n";
    $output .= "    <pubDate>";
    $output .= date_format(date_create($date, timezone_open('GMT')), DATE_RFC2822);
    $output .= "</pubDate>\n";
    $output .= "  </item>\n";
    return $output;
}
 /**
  * Get weekly shedule for a particular day
  *
  * @param $timestamp
  * @return array
  */
 function getSchedule($timestamp)
 {
     if (!$this->magister->personData) {
         return 403;
     }
     $tz = timezone_open('Europe/Amsterdam');
     $tz_offset = timezone_offset_get($tz, new \DateTime('@' . $timestamp, timezone_open('UTC')));
     $timestamp += $tz_offset + 4;
     $weekstart = $this->getFirstDayOfWeek(date('Y', $timestamp), date('W', $timestamp));
     $weekend = strtotime('this Friday', $weekstart);
     $data = $this->magister->personRequest('afspraken?status=1&tot=' . date('Y-m-d', $weekend) . '&van=' . date('Y-m-d', $weekstart))->Items;
     $result = array('week_timestamp' => $weekstart, 'days' => array());
     $curday = $weekstart;
     while ($curday <= $weekend) {
         $result['days'][(int) date('w', $curday)] = array('day_title' => $this->dutchDayName($curday), 'day_ofweek' => (int) date('w', $curday), 'items' => array());
         $curday += 86400;
     }
     foreach ($data as $item) {
         $start = strtotime($item->Start) + $tz_offset;
         $curwd = date('w', $start);
         if ($item->DuurtHeleDag) {
             $result['days'][(int) $curwd]['items'][] = array('title' => $item->Omschrijving, 'subtitle' => $item->Lokatie, 'start' => $start, 'start_str' => 'DAG');
         } else {
             $result['days'][(int) $curwd]['items'][] = array('title' => $item->LesuurVan . '. ' . $item->Vakken[0]->Naam, 'subtitle' => 'Lokaal ' . $item->Lokalen[0]->Naam, 'start' => $start, 'start_str' => date('H:i', $start + $tz_offset));
         }
     }
     foreach ($result['days'] as $index => $day) {
         if (empty($day['items'])) {
             unset($result['days'][$index]);
         }
     }
     return $result;
 }
示例#5
0
 function sendDataToAPI($data)
 {
     //get JSON from Source and parse it
     $arr = json_decode($data, true);
     $date = DateTime::createFromFormat("U", $arr["timestamp"], timezone_open("Europe/Berlin"));
     $date = date_format($date, 'Y-m-d');
     //Make a new JSON in the format described on page X of the API Documentation
     $json = '{
                 "originalId":"11111",
                 "attributes":{
                 },
                 "externalSourceId":36,
                 "geoBlobDates":[
                 {
                 "valid":{
                 "since":"' . $date . '",
                 "until":"3000-01-01"
                 }
                 },
                 {
                 "valid":{
                 "since":"' . $date . '",
                 "until":"3000-01-01"
                 }
                 }
                 ],
                 "tagDates":[
                 {
                 "tags":{
                 "data":"true",
                 "substance":"' . $arr["substance"] . '",
                 "value":"' . $arr["value"] . '",
                 "unit":"' . $arr["unit"] . '",
                 "timestamp":' . $arr["timestamp"] . '
                 },
                 "valid":{
                 "since":"' . $date . '",
                 "until":"3000-01-01"
                 }
                 }
                 ],
                 "geometricObjects":[
                 {
                 "valid":{
                 "since":"' . $date . '",
                 "until":"' . $date . '"
                 },
                 "multipoint":"MULTIPOINT(' . $arr["lon"] . ' ' . $arr["lat"] . ' 0)"
                 }
                 ]
               }';
     //send this
     $url = "http://ohsm.f4.htw-berlin.de:8080/OhdmApi/geographicObject/";
     $connection_options = $this->buildConnection("PUT", $json);
     $arr["response"] = file_get_contents($url, false, $connection_options);
     $arr["status"] = substr($http_response_header[0], 9, 3);
     //return the answer
     return $arr;
 }
示例#6
0
function sortPublishDateDesc($fb, $sb)
{
    if (date_create_from_format("Y-m-d", $fb[4], timezone_open("Europe/Sofia")) > date_create_from_format("Y-m-d", $sb[4], timezone_open("Europe/Sofia"))) {
        return -1;
    } else {
        return 1;
    }
}
示例#7
0
 public function isValid($value)
 {
     $this->setValue($value);
     if (!timezone_open($value)) {
         $this->error(self::INVALID_TIMEZONE);
         return false;
     }
     return true;
 }
示例#8
0
文件: Carbon.php 项目: igez/gaiaehr
 protected static function safeCreateDateTimeZone($object)
 {
     if ($object instanceof \DateTimeZone) {
         return $object;
     }
     $tz = @timezone_open((string) $object);
     if ($tz === false) {
         throw new \InvalidArgumentException('Unknown or bad timezone (' . $object . ')');
     }
     return $tz;
 }
function printChange($tag, $change)
{
    $output = "<tr>";
    //$time = time($change["time"]);
    $time = $change["time"];
    $time = date_create($change["time"], timezone_open('GMT'));
    //$time = date_format($time, "F j, Y \a\\t g:i a e");
    $time = date_format($time, "F j, Y");
    switch ($change["type"]) {
        case "creation":
            $output .= "<td>created statement";
            $output .= "<td>in <code>" . $change["file"] . ".tex</code>";
            if ($change["label"] != "") {
                $output .= "<br>label <code>" . $change["label"] . "</code>";
            }
            $output .= "<td>" . $time;
            $output .= "<td><a href='" . GitHubCommitLinesLink($change) . "'>link</a>";
            break;
        case "label":
            $output .= "<td>changed label";
            $output .= "<td>label <code>" . $change["label"] . "</code>";
            $output .= "<td>" . $time;
            $output .= "<td><a href='" . GitHubCommitLinesLink($change) . "'>diff</a>";
            break;
        case "move":
            $output .= "<td>moved the tag";
            $output .= "<td>";
            $output .= "<td>" . $time;
            break;
        case "move file":
            $output .= "<td>moved the tag";
            $output .= "<td>to <code>" . $change["file"] . ".tex</code>";
            $output .= "<td>" . $time;
            break;
        case "proof":
        case "statement":
        case "statement and proof":
            $output .= "<td>changed " . $change["type"];
            $output .= "<td>";
            $output .= "<td>" . $time;
            $output .= "<td><a href='" . GitHubDiffLink($change) . "'>diff</a>";
            break;
        case "tag":
            $output .= "<td>assigned tag";
            $output .= "<td><var>" . $tag . "</var>";
            $output .= "<td>" . $time;
            $output .= "<td>";
            break;
    }
    $output .= "</tr>";
    return $output;
}
示例#10
0
function parseInputList()
{
    $list = $_GET['list'];
    $lines = preg_split('/\\n/', $list);
    $result = [];
    //var_dump($lines);
    foreach ($lines as $line) {
        $tempDate = date_create($line, timezone_open("Europe/Sofia"));
        if ($line != "" && $tempDate) {
            $result[] = $tempDate;
        }
    }
    return $result;
}
示例#11
0
 /**
  * Calculates date interval from $dateTime (given in current format) to current datetime
  *
  * @param string $format
  * @param string $dateTime
  *
  * @return \DateInterval
  */
 public static function calculateDistance($dateTime, $format = null)
 {
     if ($dateTime == '') {
         return array();
     }
     if ($format == null) {
         $format = $_SESSION['formats']['datetime_php'];
     }
     $date = \DateTime::createFromFormat($format, $dateTime, timezone_open('UTC'));
     $now = new \DateTime('now', timezone_open('UTC'));
     $interval = (array) $date->diff($now);
     $interval['expired'] = $interval['invert'] == 0 ? 1 : 0;
     return $interval;
 }
	/**
	 * Return a set of timezone information relevant to this joyful stuff :D
	 */
	public static function zoneInfo() {
		$zones = array();
		$now = date_create();
		foreach( timezone_identifiers_list() as $tz ) {
			$zone = timezone_open( $tz );

			$name = timezone_name_get( $zone );
			$location = timezone_location_get( $zone );
			$offset = timezone_offset_get( $zone, $now ) / 60; // convert seconds to minutes

			$zones[] = array('name' => $name, 'offset' => $offset, 'location' => $location);
		}
		return $zones;
	}
示例#13
0
 /**
  * Getter for the start timestamp.
  *
  * @param int $index
  *   The index of the field value to be retrieved. Defaults to 0.
  *
  * @return int
  *   The start date as a UNIX timestamp.
  */
 protected function getStartTimeStamp($index = 0)
 {
     $value = $this->fieldItemList->getValue()[$index]['value'];
     $field_def = $this->fieldItemList->getFieldDefinition();
     $field_type = $field_def->getFieldStorageDefinition()->getType();
     if ($field_type == 'datetime') {
         /** @var \Drupal/datetime\Plugin\FieldType\DateTimeItem $field */
         $field = $this->fieldItemList->get($index);
         // Set User's Timezone
         $field->date->setTimezone(timezone_open(drupal_get_user_timezone()));
         // Format to timestamp.
         return $field->date->format('U');
     }
     return (int) $value;
 }
示例#14
0
 /**
  * Creates a new timezone from a given name.
  *
  * @param   string timezone name or NULL to use default timezone
  * @throws  lang.IllegalArgumentException if timezone is unknown
  */
 public function __construct($tz)
 {
     switch (TRUE) {
         case is_string($tz):
             $this->tz = timezone_open($tz);
             break;
         case is_null($tz):
             $this->tz = timezone_open(date_default_timezone_get());
             break;
         case $tz instanceof DateTimeZone:
             $this->tz = $tz;
     }
     if (!$this->tz instanceof DateTimeZone) {
         $e = new IllegalArgumentException('Invalid timezone identifier given: "' . $tz . '"');
         xp::gc(__FILE__);
         throw $e;
     }
 }
function printComment($comment)
{
    global $config;
    $output = "";
    $tag = getTag($comment['tag']);
    $date = date_create($comment['date'], timezone_open('GMT'));
    $output .= "<li>On " . date_format($date, 'F j') . " ";
    if (empty($comment['site'])) {
        $output .= htmlspecialchars($comment['author']);
    } else {
        $output .= "<a href='" . htmlspecialchars($comment['site']) . "'>" . htmlspecialchars($comment['author']) . "</a>";
    }
    $output .= " left <a href='" . href("tag/" . $comment["tag"] . "#comment-" . $comment['id']) . "'>comment " . $comment['id'] . "</a>";
    $output .= " on <a href='" . href('tag/' . $comment['tag']) . "'>tag <var title='" . $tag['label'] . "'>" . $comment['tag'] . "</var></a>";
    $output .= "<blockquote>";
    $output .= htmlentities(substr($comment['comment'], 0, $config["comments cutoff"])) . (strlen($comment['comment']) > $config["comments cutoff"] ? '...' : '');
    $output .= "</blockquote>";
    return $output;
}
示例#16
0
 /**
  * Constructor. Creates a new date object through either a
  * <ul>
  *   <li>integer - interpreted as timestamp</li>
  *   <li>string - parsed into a date</li>
  *   <li>php.DateTime object - will be used as is</li>
  *   <li>NULL - creates a date representing the current instance</li>
  *  </ul>
  *
  * Timezone assignment works through these rules:
  * . If the time is given as string and contains a parseable timezone identifier
  *   that one is used.
  * . If no timezone could be determined, the timezone given by the
  *   second parameter is used
  * . If no timezone has been given as second parameter, the system's default
  *   timezone is used.
  *
  * @param   var in default NULL either a string or a Unix timestamp or DateTime object, defaulting to now
  * @param   string timezone default NULL string of timezone
  * @throws  lang.IllegalArgumentException in case the date is unparseable
  */
 public function __construct($in = null, TimeZone $timezone = null)
 {
     if ($in instanceof \DateTime) {
         $this->date = $in;
     } else {
         if ((string) (int) $in === (string) $in) {
             // Specially mark timestamps for parsing (we assume here that strings
             // containing only digits are timestamps)
             $this->date = date_create('@' . $in, timezone_open('UTC'));
             date_timezone_set($this->date, $timezone ? $timezone->getHandle() : timezone_open(date_default_timezone_get()));
         } else {
             try {
                 $this->date = $timezone ? new \DateTime($in, $timezone->getHandle()) : new \DateTime($in);
             } catch (\Exception $e) {
                 throw new IllegalArgumentException('Given argument is neither a timestamp nor a well-formed timestring: ' . \xp::stringOf($in));
             }
         }
     }
 }
示例#17
0
 /**
  * Constructor. Creates a new date object through either a
  * <ul>
  *   <li>integer - interpreted as timestamp</li>
  *   <li>string - parsed into a date</li>
  *   <li>php.DateTime object - will be used as is</li>
  *   <li>NULL - creates a date representing the current instance</li>
  *  </ul>
  *
  * Timezone assignment works through these rules:
  * . If the time is given as string and contains a parseable timezone identifier
  *   that one is used.
  * . If no timezone could be determined, the timezone given by the
  *   second parameter is used
  * . If no timezone has been given as second parameter, the system's default
  *   timezone is used.
  *
  * @param   var in default NULL either a string or a Unix timestamp or DateTime object, defaulting to now
  * @param   string timezone default NULL string of timezone
  * @throws  lang.IllegalArgumentException in case the date is unparseable
  */
 public function __construct($in = NULL, TimeZone $timezone = NULL)
 {
     if ($in instanceof DateTime) {
         $this->date = $in;
     } else {
         if ((string) (int) $in === (string) $in) {
             // Specially mark timestamps for parsing (we assume here that strings
             // containing only digits are timestamps)
             $this->date = date_create('@' . $in, timezone_open('UTC'));
             date_timezone_set($this->date, $timezone ? $timezone->getHandle() : timezone_open(date_default_timezone_get()));
         } else {
             $this->date = $timezone ? date_create($in, $timezone->getHandle()) : date_create($in);
             if (FALSE === $this->date || xp::errorAt(__FILE__, __LINE__ - 1)) {
                 $e = new IllegalArgumentException('Given argument is neither a timestamp nor a well-formed timestring: ' . xp::stringOf($in));
                 xp::gc(__FILE__);
                 throw $e;
             }
         }
     }
 }
示例#18
0
 /**
  * Creates a new timezone from a given name.
  *
  * @param   string timezone name or NULL to use default timezone
  * @throws  lang.IllegalArgumentException if timezone is unknown
  */
 public function __construct($tz)
 {
     if (null === $tz) {
         $this->tz = timezone_open(date_default_timezone_get());
     } else {
         if (is_string($tz)) {
             try {
                 $this->tz = new \DateTimeZone($tz);
             } catch (\Throwable $e) {
                 throw new IllegalArgumentException('Invalid timezone identifier given: ' . $e->getMessage());
             }
         } else {
             if ($tz instanceof \DateTimeZone) {
                 $this->tz = $tz;
             } else {
                 throw new IllegalArgumentException('Expecting NULL, a string or a DateTimeZone instance, have ' . \xp::typeOf($tz));
             }
         }
     }
 }
示例#19
0
 /**
  * Set timezone
  *
  * Sets the timezone value. This method accepts timezone names as strings.
  * You can get the full list of accepted values in the PHP manual: {@link
  * http://php.net/manual/en/timezones.php} (note, some timezones inside the
  * Others are not accepted):
  * <code> $tz   = new AeDate_Timezone('Europe/Amsterdam');
  * $date = new AeDate('2009-05-12 14:00:00', 'Europe/Moscow');
  *
  * echo $date; // Tue, 12 May 2009 14:00:00 +0400
  * echo $date->setTimezone($tz); // Tue, 12 May 2009 12:00:00 +0200</code>
  *
  * @throws AeDateTimezoneException #400 on invalid value
  * @throws AeDateTimezoneException #413 on unrecognized timezone identifier
  *
  * @param string|DateTimeZone $value
  *
  * @return AeDate_Timezone self
  */
 public function setValue($value)
 {
     if ($value instanceof AeString) {
         $value = $value->getValue();
     }
     if (!is_string($value) && !$value instanceof DateTimeZone) {
         throw new AeDateTimezoneException('Invalid value passed: expecting string or DateTimeZone, ' . AeType::of($value) . ' given', 400);
     }
     if (!$value instanceof DateTimeZone) {
         if (strpos($value, ' ') !== false) {
             $value = str_replace(' ', '_', trim($value));
         }
         $zone = @timezone_open($value);
         if (!$zone) {
             throw new AeDateTimezoneException('Unrecognized timezone identifier: ' . $value, 413);
         }
         $value = $zone;
     }
     $this->_value = $value;
     return $this;
 }
示例#20
0
 function __construct($connect_data)
 {
     $this->tz_offset = timezone_offset_get(timezone_open(date_default_timezone_get()), new DateTime());
     $this->FTP_STATE_NAME = array(0 => 'DISCONNECTED', 1 => 'CONNECTED', 2 => 'LOGGED IN', 3 => 'TARGETED');
     $this->FTP_STATUS_NAME = array(-1 => 'ERROR', 0 => 'READY', 1 => 'READING', 2 => 'NOT READ');
     $this->months = array("Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12);
     $this->user = $connect_data['username'];
     $this->pass = $connect_data['password'];
     $this->listing_cache = array();
     if (isset($connect_data['port'])) {
         $this->port = $connect_data['port'];
     } else {
         $this->port = 21;
     }
     $this->host = $connect_data['host'];
     if (isset($connect_data['path'])) {
         $this->cur_path = $connect_data['path'];
     } else {
         $this->cur_path = '';
     }
 }
示例#21
0
function validatePin($pin, $gender)
{
    $year = substr($pin, 0, 2);
    $month = substr($pin, 2, 2);
    $day = substr($pin, 4, 2);
    if ($month > 40) {
        $month -= 40;
        $year = "20" . $year;
    } elseif ($month > 20) {
        $year = "18" . $year;
        $month -= 20;
    } else {
        $year = "19" . $year;
    }
    $dateStr = $day . "-" . $month . "-" . $year;
    $date = date_create($dateStr, timezone_open("Europe/Sofia"));
    if (!$date) {
        return false;
    }
    $monthChk = date_format($date, "m");
    if ($monthChk != $month) {
        return false;
    }
    $genderChk = substr($pin, 8, 1);
    if ($genderChk % 2 != $gender) {
        return false;
    }
    $sumChk = substr($pin, 9, 1);
    $weights = [2, 4, 8, 5, 10, 9, 7, 3, 6];
    $sum = 0;
    for ($i = 0; $i < 9; $i++) {
        $sum += substr($pin, $i, 1) * $weights[$i];
    }
    $sum = $sum % 11 % 10;
    if ($sum != $sumChk) {
        return false;
    }
    return true;
}
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     foreach ($items as $delta => $item) {
         $output = '';
         if (!empty($item->date)) {
             // The date was created and verified during field_load(), so it is safe
             // to use without further inspection.
             $date = $item->date;
             $date->setTimeZone(timezone_open(drupal_get_user_timezone()));
             $format = DATETIME_DATETIME_STORAGE_FORMAT;
             if ($this->getFieldSetting('datetime_type') == 'date') {
                 // A date without time will pick up the current time, use the default.
                 datetime_date_default_time($date);
                 $format = DATETIME_DATE_STORAGE_FORMAT;
             }
             $output = $date->format($format);
         }
         $elements[$delta] = array('#markup' => $output);
     }
     return $elements;
 }
示例#23
0
 /**
  * Returns ISO 8601 formatted datetime: 2011-12-08T01:15:36-08:00
  *
  * @param $date_gmt (string) GMT datetime string.
  * @param $date (string) Optional.  Used to calculate the offset from GMT.
  *
  * @return string
  */
 static function format_date($date_gmt, $date = null)
 {
     $timestamp_gmt = strtotime("{$date_gmt}+0000");
     if (null === $date) {
         $timestamp = $timestamp_gmt;
         $hours = $minutes = $west = 0;
     } else {
         $date_time = date_create("{$date}+0000");
         if ($date_time) {
             $timestamp = date_format($date_time, 'U');
         } else {
             $timestamp = 0;
         }
         // "0000-00-00 00:00:00" == -62169984000
         if (-62169984000 == $timestamp_gmt) {
             // WordPress sets post_date=now, post_date_gmt="0000-00-00 00:00:00" for all drafts
             // WordPress sets post_modified=now, post_modified_gmt="0000-00-00 00:00:00" for new drafts
             // Try to guess the correct offset from the blog's options.
             $timezone_string = get_option('timezone_string');
             if ($timezone_string && $date_time) {
                 $timezone = timezone_open($timezone_string);
                 if ($timezone) {
                     $offset = $timezone->getOffset($date_time);
                 }
             } else {
                 $offset = 3600 * get_option('gmt_offset');
             }
         } else {
             $offset = $timestamp - $timestamp_gmt;
         }
         $west = $offset < 0;
         $offset = abs($offset);
         $hours = (int) floor($offset / 3600);
         $offset -= $hours * 3600;
         $minutes = (int) floor($offset / 60);
     }
     return (string) gmdate('Y-m-d\\TH:i:s', $timestamp) . sprintf('%s%02d:%02d', $west ? '-' : '+', $hours, $minutes);
 }
示例#24
0
function mydatefunc($dt)
{
    $tzs = 'America/Chicago';
    //todo: get timezone from company table of database. if isnull db_timezone, $tzs =
    // 'America/Chicago';, else, $tzs = db_timezone.
    date_default_timezone_set($tzs);
    // sets default timezone for all new dates here to tzs
    $mydate = date_create("{$dt}", timezone_open($tzs));
    // create new date objects
    //parsing date parts to values (numbers)
    $year = $mydate->format('Y');
    $month = $mydate->format('m');
    $day = $mydate->format('d');
    $hour = $mydate->format('H');
    $mins = $mydate->format('i');
    $secs = $mydate->format('s');
    //$ampm = $mydate->format('A');
    $x = $year . '-' . $month . '-' . $day . 'T' . $hour . ':' . $mins . ':' . $secs . '.000';
    // building and pushing into input box (readonly)
    //writing three formats of current date/time to session variables
    $_SESSION["mydatestring"] = $x;
    //built to go into input type="datetime-local" boxes
    $_SESSION["mydatew3c"] = date_format($mydate, DATE_W3C);
    //mysql
    $_SESSION["mydateatom"] = date_format($mydate, DATE_ATOM);
    //another format for php
    /*  for feedback and debugging only:
        $z = $_SESSION["mydatestring"];
        echo "<input type=\"datetime-local\" id=\"myLocalDate\" value=$x readonly><br>";
        echo 'Time Zone Applied = ' . date_default_timezone_get() . '<br />';
        echo $z . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Reading from session mydatestring <br>";
        echo date_format($mydate, DATE_W3C) . " " . $mydate->format('T') . "  -  W3C writing to session  <br>";
        echo $_SESSION["mydatew3c"] . " " . "  -  W3C reading from session mydatew3c <br>";
        echo date_format($mydate, DATE_ATOM) . " " . $mydate->format('T') . "  -  ATOM writing to session  <br>";
        echo $_SESSION["mydateatom"] . " " . "  -  ATOM reading from session mydateatom <br>";*/
    /* alternative conversion method: $mydateatom = $mydate->format(DateTime::ATOM);
       echo ($mydateatom . " " . $mydate->format('T') . "  -  ATOM format  <br>");*/
}
示例#25
0
/**
 * Diese Funktion transformiert die Daten, die von der Funktion getAppointmentByResource erstellt wurden,
 * in eine Datenstruktur, die auf der Oberfläche geparsed und angezeigt werden kann.
 */
function transformAppointmentsToHtml($result, $exclude_id, $class, $tag_ende, $tag_offset)
{
    $data = "";
    foreach ($result as $values) {
        $appointment_id = $values["ID"];
        $output = getEventOfAppointment($appointment_id);
        $output .= getRessourcesOfAppointment($appointment_id, $exclude_id);
        $duration = ($values["end_ts"] - $values["begin_ts"]) / 3600;
        //Achtung: begin_ts ist der timestamp des ersten TERMINS! Wir erhalten also in der Differenz mit dem Anfragedatum mehrere Tage Unterschied
        //AUSSERDEM: Zeitzonen-Problem!!!!
        //Erster Schritt: Berechne die Anzahl der Tage die zwischen dem ersten Serientermin und heute liegt:
        $anzahlTage = floor(($tag_ende - $values["begin_ts"]) / SECS_PER_DAY);
        //Zweiter Schritt: Prüfe die Gleichheit der Zeitzonen!
        $objDateTimeZone = timezone_open(date_default_timezone_get());
        $date = date("Y-m-d h:i:s", $values["begin_ts"]);
        $timezoneDiffOriginal = $strZeitzoneUnterschiedZuGMT = timezone_offset_get($objDateTimeZone, date_create($date, $objDateTimeZone));
        $timezoneDiffCurrent = $strZeitzoneUnterschiedZuGMT = timezone_offset_get($objDateTimeZone, date_create("now", $objDateTimeZone));
        //echo "begin_ts:".$values["begin_ts"]."anzahlTage:".$anzahlTage."tag_offset:".$tag_offset."tag_ende:".$tag_ende;
        $start = ($values["begin_ts"] + $anzahlTage * SECS_PER_DAY - $tag_offset) / 3600 + ($timezoneDiffOriginal - $timezoneDiffCurrent) / 3600;
        $data .= "<li class='" . $class . "' data-start='" . $start . "' data-duration='" . $duration . "'><ul class='ttEventDetails'>" . $output . "</ul></li>";
    }
    return $data;
}
示例#26
0
 /**
  * The magic function that does everything.
  * 
  **/
 function magic2()
 {
     if (!in_array($this->tz_file, $this->valid_names)) {
         trigger_error(sprintf('Bad timezone name given: %s', $this->tz_file), E_USER_ERROR);
     }
     // TODO: move msg to lang
     $tz_obj = timezone_open($this->tz_file);
     $tz_data = timezone_transitions_get($tz_obj);
     $last = reset($tz_data);
     $now = time();
     foreach ($tz_data as $transition) {
         if ($transition['ts'] > $now) {
             $this->gmt_offset = $last['offset'];
             $this->abba = $last['abbr'];
             $this->next_update = $transition['ts'];
             return;
         } else {
             $last = $transition;
         }
     }
     // default to the last entry if we get here
     $this->gmt_offset = $last['offset'];
     $this->abba = $last['abbr'];
 }
示例#27
0
 /**
  * returns a string from array returned by Date::timeAgo()
  * @param $time unix epoch
  * @param $from from unix epoch
  * @param $format array of periods to show
  */
 public static function formatTimeAgo($from, $to, $format = array('year', 'month', 'day', 'hour', 'minute', 'second'))
 {
     // have to calculate the offset
     $default_timezone = timezone_open(date_default_timezone_get());
     $from_datetime = new DateTime(date('Y-m-d H:i:s', $from));
     // add the offset
     $from += timezone_offset_get($default_timezone, $from_datetime);
     $timeago = Date::timeAgo($from, $to);
     $t = array();
     foreach ($format as $period) {
         if (isset($timeago[$period])) {
             $time = $timeago[$period];
             if ($time != 1) {
                 $period .= 's';
             }
             $t[] = "{$time} [{$period}]";
         }
     }
     $t = implode(" ", $t);
     if (!trim($t)) {
         return (string) '0';
     }
     return $t;
 }
示例#28
0
 /**
  * Get weekly shedule for a particular day
  *
  * @param $timestamp
  * @return array
  */
 function getSchedule($timestamp)
 {
     if (!$this->zermelo->token) {
         return 403;
     }
     $subjects = (array) json_decode(file_get_contents('lib/Assets/subjects.json'));
     $tz = timezone_open('Europe/Amsterdam');
     $tz_offset = timezone_offset_get($tz, new \DateTime('@' . $timestamp, timezone_open('UTC')));
     $timestamp += $tz_offset + 4;
     $weekstart = $this->getFirstDayOfWeek(date('Y', $timestamp), date('W', $timestamp));
     $weekend = strtotime('this Friday', $weekstart);
     $result = array('week_timestamp' => $weekstart, 'days' => array());
     $curday = $weekstart;
     while ($curday <= $weekend) {
         $curwd = (int) date('w', $curday);
         $result['days'][$curwd] = array('day_title' => $this->dutchDayName($curday), 'day_ofweek' => (int) date('w', $curday), 'items' => array());
         $start = $curday;
         $end = $curday + 86399;
         $data = $this->zermelo->getStudentGrid($start, $end);
         foreach ($data as $item) {
             $item = (object) $item;
             $start = (int) $item->start;
             $vakname = isset($subjects[$item->subjects[0]]) ? $subjects[$item->subjects[0]] : $item->subjects[0];
             $teacher = $item->teachers[0];
             $cancelled = $item->cancelled;
             $moved = $item->moved;
             $teacher = preg_replace('/^.*-\\s*/', '', $teacher);
             if (empty($item->locations)) {
                 $item->locations = array('onbekend');
             }
             $result['days'][$curwd]['items'][] = array('title' => $vakname, 'subtitle' => 'Lokaal ' . $item->locations[0], 'teacher' => strtoupper($teacher), 'cancelled' => $cancelled, 'moved' => $moved, 'start' => $start, 'start_str' => date('H:i', $start + $tz_offset));
         }
         $curday += 86400;
     }
     return $result;
 }
示例#29
0
	/**
	 * @param $context IContextSource
	 * @return array
	 */
	static function getTimezoneOptions( IContextSource $context ) {
		$opt = array();

		global $wgLocalTZoffset;
		$timestamp = MWTimestamp::getLocalInstance();
		// Check that $wgLocalTZoffset is the same as the local time zone offset
		if ( $wgLocalTZoffset == $timestamp->format( 'Z' ) / 60 ) {
			$server_tz_msg = $context->msg( 'timezoneuseserverdefault', $timestamp->getTimezone()->getName() )->text();
		} else {
			$tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 );
			$server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
		}
		$opt[$server_tz_msg] = "System|$wgLocalTZoffset";
		$opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
		$opt[$context->msg( 'guesstimezone' )->text()] = 'guess';

		if ( function_exists( 'timezone_identifiers_list' ) ) {
			# Read timezone list
			$tzs = timezone_identifiers_list();
			sort( $tzs );

			$tzRegions = array();
			$tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
			$tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
			$tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
			$tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
			$tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
			$tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
			$tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
			$tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
			$tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
			$tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
			asort( $tzRegions );

			$prefill = array_fill_keys( array_values( $tzRegions ), array() );
			$opt = array_merge( $opt, $prefill );

			$now = date_create( 'now' );

			foreach ( $tzs as $tz ) {
				$z = explode( '/', $tz, 2 );

				# timezone_identifiers_list() returns a number of
				# backwards-compatibility entries. This filters them out of the
				# list presented to the user.
				if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) ) {
					continue;
				}

				# Localize region
				$z[0] = $tzRegions[$z[0]];

				$minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );

				$display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
				$value = "ZoneInfo|$minDiff|$tz";

				$opt[$z[0]][$display] = $value;
			}
		}
		return $opt;
	}
 /**
  * filter hook for modifying a field's input tag (e.g. on custom fields)
  * @param string $input the input tag before modification
  * @param array $field
  * @param string $value
  * @param integer $lead_id
  * @param integer $form_id
  * @return string
  */
 public function gformFieldInput($input, $field, $value, $lead_id, $form_id)
 {
     if ($field['type'] == GFEWAY_FIELD_RECURRING) {
         // pick up the real value
         $value = rgpost('gfeway_' . $field['id']);
         $css = isset($field['cssClass']) ? esc_attr($field['cssClass']) : '';
         $today = date_create('now', timezone_open('Australia/Sydney'));
         $initial_amount = empty($value[1]) ? '0.00' : $value[1];
         $initial_date = empty($value[2]) ? $today->format('d-m-Y') : $value[2];
         $recurring_amount = empty($value[3]) ? '0.00' : $value[3];
         $start_date = empty($value[4]) ? $today->format('d-m-Y') : $value[4];
         $end_date = empty($value[5]) ? '31-12-2099' : $value[5];
         $interval_type = empty($value[6]) ? 'monthly' : $value[6];
         $input = "<div class='ginput_complex ginput_container gfeway_recurring_complex {$css}' id='input_{$field['id']}'>";
         // initial amount
         $sub_field = array('type' => 'donation', 'id' => $field['id'], 'sub_id' => '1', 'label' => empty($field['gfeway_initial_amount_label']) ? self::$defaults['gfeway_initial_amount_label'] : $field['gfeway_initial_amount_label'], 'isRequired' => false, 'size' => 'medium', 'label_class' => 'gfeway_initial_amount_label', 'hidden' => isset($field['gfeway_initial_setting']) ? !$field['gfeway_initial_setting'] : false);
         $input .= $this->fieldDonation($sub_field, $initial_amount, $lead_id, $form_id);
         // initial date
         $sub_field = array('type' => 'date', 'id' => $field['id'], 'sub_id' => '2', 'label' => empty($field['gfeway_initial_date_label']) ? self::$defaults['gfeway_initial_date_label'] : $field['gfeway_initial_date_label'], 'dateFormat' => 'dmy', 'dateType' => 'datepicker', 'dateMin' => '+0', 'dateMax' => '+2Y', 'calendarIconType' => 'calendar', 'isRequired' => false, 'size' => 'medium', 'label_class' => 'gfeway_initial_date_label', 'hidden' => isset($field['gfeway_initial_setting']) ? !$field['gfeway_initial_setting'] : false);
         $input .= $this->fieldDate($sub_field, $initial_date, $lead_id, $form_id);
         $input .= '<br />';
         // recurring amount
         $sub_field = array('type' => 'donation', 'id' => $field['id'], 'sub_id' => '3', 'label' => empty($field['gfeway_recurring_amount_label']) ? self::$defaults['gfeway_recurring_amount_label'] : $field['gfeway_recurring_amount_label'], 'isRequired' => true, 'size' => 'medium', 'label_class' => 'gfeway_recurring_amount_label');
         $input .= $this->fieldDonation($sub_field, $recurring_amount, $lead_id, $form_id);
         // start date
         $sub_field = array('type' => 'date', 'id' => $field['id'], 'sub_id' => '4', 'label' => empty($field['gfeway_start_date_label']) ? self::$defaults['gfeway_start_date_label'] : $field['gfeway_start_date_label'], 'dateFormat' => 'dmy', 'dateType' => 'datepicker', 'dateMin' => '+0', 'dateMax' => '+2Y', 'calendarIconType' => 'calendar', 'isRequired' => true, 'size' => 'medium', 'label_class' => 'gfeway_start_date_label', 'hidden' => empty($field['gfeway_recurring_date_start']) && empty($field['gfeway_recurring_date_setting']));
         $input .= $this->fieldDate($sub_field, $start_date, $lead_id, $form_id);
         // end date
         $sub_field = array('type' => 'date', 'id' => $field['id'], 'sub_id' => '5', 'label' => empty($field['gfeway_end_date_label']) ? self::$defaults['gfeway_end_date_label'] : $field['gfeway_end_date_label'], 'dateFormat' => 'dmy', 'dateType' => 'datepicker', 'dateMin' => '+0', 'dateMax' => '2099-12-31', 'calendarIconType' => 'calendar', 'isRequired' => true, 'size' => 'medium', 'label_class' => 'gfeway_end_date_label', 'hidden' => empty($field['gfeway_recurring_date_end']) && empty($field['gfeway_recurring_date_setting']));
         $input .= $this->fieldDate($sub_field, $end_date, $lead_id, $form_id);
         $input .= '<br />';
         // recurrance interval type drop-down
         $sub_field = array('type' => 'number', 'id' => $field['id'], 'sub_id' => '6', 'label' => empty($field['gfeway_interval_type_label']) ? self::$defaults['gfeway_interval_type_label'] : $field['gfeway_interval_type_label'], 'isRequired' => true, 'size' => 'medium', 'label_class' => 'gfeway_interval_type_label');
         $input .= $this->fieldIntervalType($sub_field, $interval_type, $lead_id, $form_id);
         // concatenated value added to database
         $sub_field = array('type' => 'hidden', 'id' => $field['id'], 'isRequired' => true);
         $input .= $this->fieldConcatenated($sub_field, $interval_type, $lead_id, $form_id);
         $input .= '</div>';
     }
     return $input;
 }