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());
89 return array(
'timezone',
'default_timezone',
'unix');
107 return $this->unix ? false :
true;
126 $this->log->write(
'Unsupported timezone given: '.$a_timezone_identifier);
127 throw new ilDateTimeException(
'Unsupported timezone given. Timezone: '.$a_timezone_identifier);
139 return $this->timezone->getIdentifier();
158 switch($a_compare_field)
189 switch($a_compare_field)
221 switch($a_compare_field)
264 $count_str = $a_count > 0 ? (
'+'.$a_count.
' ') : ($a_count.
' ');
266 $this->timezone->switchTZ();
270 $this->unix = strtotime($count_str.
'year',$this->unix);
274 $this->unix = strtotime($count_str.
'month',$this->unix);
278 $this->unix = strtotime($count_str.
'week',$this->unix);
282 $this->unix = strtotime($count_str.
'day',$this->unix);
286 $this->unix = strtotime($count_str.
'hour',$this->unix);
291 $this->unix = strtotime($count_str.
'minute',$this->unix);
298 $this->timezone->restoreTZ();
322 $this->timezone->switchTZ();
324 $offset = mktime(0,0,0,2,1,1970) - gmmktime(0,0,0,2,1,1970);
325 $this->timezone->restoreTZ();
342 $this->unix = $a_date;
346 $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);
349 $this->log->write(__METHOD__.
': Cannot parse date: '.$a_date);
350 $this->log->write(__METHOD__.
': '.print_r($matches,
true));
351 $this->log->logStack();
356 if($d_parts[9] ==
'Z')
363 $this->timezone->switchTZ();
365 $this->unix = mktime(
366 isset($d_parts[5]) ? $d_parts[5] : 0,
367 isset($d_parts[6]) ? $d_parts[6] : 0,
368 isset($d_parts[7]) ? $d_parts[7] : 0,
373 if($d_parts[0] ==
'0000-00-00 00:00:00')
378 if($d_parts[9] ==
'Z')
384 $this->timezone->restoreTZ();
392 $unix = strtotime($a_date);
396 $this->log->write(__METHOD__.
': Cannot parse date : '.$a_date);
404 if (!isset($a_date[
'seconds']))
406 $a_date[
'seconds'] =
false;
409 $this->timezone->switchTZ();
410 $this->unix = mktime(
417 $this->timezone->restoreTZ();
427 if(preg_match(
"/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $a_date,$d_parts) ==
false)
429 $this->log->write(__METHOD__.
': Cannot parse date: '.$a_date);
432 $this->timezone->switchTZ();
433 $this->unix = mktime(
434 isset($d_parts[4]) ? $d_parts[4] : 0,
435 isset($d_parts[5]) ? $d_parts[5] : 0,
436 isset($d_parts[6]) ? $d_parts[6] : 0,
441 if($d_parts[0] ==
'00000000000000' or
442 $d_parts[0] ==
'00000000')
446 $this->timezone->restoreTZ();
450 $dt = DateTime::createFromFormat(DateTime::ISO8601, $a_date);
451 $this->unix = $dt->getTimeStamp();
466 public function get($a_format,$a_format_str =
'',$a_tz =
'')
476 $this->log->write(__METHOD__.
': Invalid timezone given. Timezone: '.$a_tz);
481 #$timezone = $this->timezone; 515 $date[
'isoday'] = $date[
'wday'] == 0 ? 7 : $date[
'wday'];
__construct($a_date=null, $a_format=0, $a_tz='')
Create new date object.
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
switchTimeZone($a_timezone_identifier='')
Switch timezone.
Class for DateTime exceptions.
__toString()
to string for date time objects Output is user time zone
getTimeZoneIdentifier()
get timezone identifier
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
getUTCOffset()
get UTC offset
Class for TimeZone exceptions.
get($a_format, $a_format_str='', $a_tz='')
get formatted date
increment($a_type, $a_count=1)
increment
static _getInstance($a_tz='')
get instance by timezone
getUnixTime()
get unix time
setDate($a_date, $a_format)
set date
static _within(ilDateTime $dt, ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check whether an date is within a date duration given by start and end.
isNull()
Check if a date is null (Datetime == '0000-00-00 00:00:00', unixtime == 0,...)