Exemplo n.º 1
0
 public function __construct($time = 'now', $timezone = null, $language = false)
 {
     try {
         parent::__construct($time, $timezone);
     } catch (Exception $e) {
         parent::__construct('now', $timezone);
         registry::register('plus_debug_logger')->log('time_error', 'Unable to create DateTime-object with given time-string \'' . $time . '\', using \'now\' as fallback.');
         registry::register('plus_debug_logger')->log('php_error', 'EXCEPTION', 0, $e->getMessage(), __FILE__, __LINE__);
     }
     self::$language = $language;
 }
Exemplo n.º 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];
 }