5 include_once(
'Services/Calendar/classes/class.ilDateTimeException.php');
6 include_once(
'Services/Calendar/classes/class.ilTimeZone.php');
9 define(
'IL_CAL_DATETIME',1);
10 define(
'IL_CAL_DATE',2);
11 define(
'IL_CAL_UNIX',3);
12 define(
'IL_CAL_FKT_DATE',4);
13 define(
'IL_CAL_FKT_GETDATE',5);
14 define(
'IL_CAL_TIMESTAMP',6);
15 define(
'IL_CAL_ISO_8601',7);
17 define(
'IL_CAL_YEAR',
'year');
18 define(
'IL_CAL_MONTH',
'month');
19 define(
'IL_CAL_WEEK',
'week');
20 define(
'IL_CAL_DAY',
'day');
21 define(
'IL_CAL_HOUR',
'hour');
60 public function __construct($a_date = null,$a_format = 0,$a_tz =
'')
77 $this->
setDate($a_date,$a_format);
82 $this->log->write(__METHOD__.
': '.$exc->getMessage());
94 return $this->unix ?
false :
true;
113 $this->log->write(
'Unsupported timezone given: '.$a_timezone_identifier);
114 throw new ilDateTimeException(
'Unsupported timezone given. Timezone: '.$a_timezone_identifier);
126 return $this->timezone->getIdentifier();
145 switch($a_compare_field)
176 switch($a_compare_field)
208 switch($a_compare_field)
251 $count_str = $a_count > 0 ? (
'+'.$a_count.
' ') : ($a_count.
' ');
253 $this->timezone->switchTZ();
257 $this->unix = strtotime($count_str.
'year',$this->unix);
261 $this->unix = strtotime($count_str.
'month',$this->unix);
265 $this->unix = strtotime($count_str.
'week',$this->unix);
269 $this->unix = strtotime($count_str.
'day',$this->unix);
273 $this->unix = strtotime($count_str.
'hour',$this->unix);
278 $this->unix = strtotime($count_str.
'minute',$this->unix);
285 $this->timezone->restoreTZ();
309 $this->timezone->switchTZ();
311 $offset = mktime(0,0,0,2,1,1970) - gmmktime(0,0,0,2,1,1970);
312 $this->timezone->restoreTZ();
329 $this->unix = $a_date;
333 $matches = preg_match(
'/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)$/i',$a_date,$d_parts);
336 $this->log->write(__METHOD__.
': Cannot parse date: '.$a_date);
337 $this->log->write(__METHOD__.
': '.print_r($matches,
true));
338 $this->log->logStack();
343 if($d_parts[9] ==
'Z')
350 $this->timezone->switchTZ();
352 $this->unix = mktime(
353 isset($d_parts[5]) ? $d_parts[5] : 0,
354 isset($d_parts[6]) ? $d_parts[6] : 0,
355 isset($d_parts[7]) ? $d_parts[7] : 0,
360 if($d_parts[0] ==
'0000-00-00 00:00:00')
365 if($d_parts[9] ==
'Z')
371 $this->timezone->restoreTZ();
379 $unix = strtotime($a_date);
383 $this->log->write(__METHOD__.
': Cannot parse date : '.$a_date);
391 if (!isset($a_date[
'seconds']))
393 $a_date[
'seconds'] =
false;
396 $this->timezone->switchTZ();
397 $this->unix = mktime(
404 $this->timezone->restoreTZ();
414 if(preg_match(
"/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $a_date,$d_parts) ==
false)
416 $this->log->write(__METHOD__.
': Cannot parse date: '.$a_date);
419 $this->timezone->switchTZ();
420 $this->unix = mktime(
421 isset($d_parts[4]) ? $d_parts[4] : 0,
422 isset($d_parts[5]) ? $d_parts[5] : 0,
423 isset($d_parts[6]) ? $d_parts[6] : 0,
428 if($d_parts[0] ==
'00000000000000' or
429 $d_parts[0] ==
'00000000')
433 $this->timezone->restoreTZ();
437 $dt = DateTime::createFromFormat(DateTime::ISO8601, $a_date);
438 $this->unix = $dt->getTimeStamp();
453 public function get($a_format,$a_format_str =
'',$a_tz =
'')
463 $this->log->write(__METHOD__.
': Invalid timezone given. Timezone: '.$a_tz);
468 #$timezone = $this->timezone;
502 $date[
'isoday'] = $date[
'wday'] == 0 ? 7 : $date[
'wday'];