Пример #1
0
 /**
  * Adds Seconds to a given UTC Timestamp. 
  * Respects Winter/Summertime, because of given Timezone of Event
  * Returns UTC Timestamp
  * 
  * @param integer $intUtcTimestamp
  * @param integer $intSecondsToAdd
  * @param string $strEventTimezone
  * @return integer UTC Timestamp
  */
 public function createRepeatableEvents($intUtcTimestamp, $intSecondsToAdd, $strEventTimezone = '')
 {
     $objTimeZone = $strEventTimezone === '' ? $this->userTimeZone : new DateTimeZone($strEventTimezone);
     $objTime = new DateTimeLocale($this->helper_dtime($intUtcTimestamp), $objTimeZone);
     $objTime->setTimezone($objTimeZone);
     if ($intSecondsToAdd > 0) {
         $objTime->add(new DateInterval("PT" . $intSecondsToAdd . "S"));
     } else {
         $objTime->sub(new DateInterval("PT" . $intSecondsToAdd . "S"));
     }
     return $objTime->format("U");
 }
Пример #2
0
 public function dateDiff($ts1, $ts2, $out = 'sec')
 {
     // Build the Dates
     if (!is_numeric($ts1)) {
         $dt1 = new DateTimeLocale($dt1, $this->userTimeZone);
         $ts1 = $dt1->format('U');
     }
     if (!is_numeric($ts2)) {
         $dt2 = new DateTimeLocale($dt2, $this->userTimeZone);
         $ts2 = $dt2->format('U');
     }
     // calculate the difference
     $secs['sec'] = 1;
     $secs['min'] = 60;
     $secs['hour'] = $secs['min'] * 60;
     $secs['day'] = $secs['hour'] * 24;
     $secs['week'] = $secs['day'] * 7;
     $secs['month'] = $secs['day'] * 30;
     $secs['year'] = $secs['day'] * 365;
     return ($ts2 - $ts1 - ($ts2 - $ts1) % $secs[$out]) / $secs[$out];
 }