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');
63 public function __construct($a_date = null, $a_format = 0, $a_tz =
'')
73 $this->
setDate($a_date, $a_format);
75 $this->log->write(__METHOD__ .
': ' . $exc->getMessage());
89 return array(
'timezone',
'default_timezone',
'dt_obj');
106 return !($this->dt_obj instanceof
DateTime);
122 $this->log->write(
'Unsupported timezone given: ' . $a_timezone_identifier);
123 throw new ilDateTimeException(
'Unsupported timezone given. Timezone: ' . $a_timezone_identifier);
135 return $this->
timezone->getIdentifier();
158 switch ($a_compare_field) {
170 return $start->dt_obj < $end->dt_obj;
193 switch ($a_compare_field) {
205 return $start->dt_obj == $end->dt_obj;
228 switch ($a_compare_field) {
240 return $start->dt_obj > $end->dt_obj;
274 $sub = ($a_count < 0);
275 $count_str = abs($a_count);
279 $count_str .=
'year';
283 $count_str .=
'month';
287 $count_str .=
'week';
295 $count_str .=
'hour';
299 $count_str .=
'minute';
303 $interval = date_interval_create_from_date_string($count_str);
305 $this->dt_obj->add($interval);
307 $this->dt_obj->sub($interval);
323 return $this->dt_obj->getTimestamp();
337 $offset = $this->dt_obj->getOffset();
345 protected function parsePartsToDate($a_year, $a_month, $a_day, $a_hour = null, $a_min = null, $a_sec = null, $a_timezone = null)
347 $a_year = (int) $a_year;
348 $a_month = (int) $a_month;
349 $a_day = (int) $a_day;
356 $a_hour = (int) $a_hour;
357 $a_min = (int) $a_min;
358 $a_sec = (int) $a_sec;
360 $format = $a_year .
'-' . $a_month .
'-' . $a_day;
362 if ($a_hour !== null) {
363 $format .=
' ' . (int) $a_hour .
':' . (
int) $a_min .
':' . (int) $a_sec;
394 $this->dt_obj = null;
403 $this->dt_obj =
new DateTime(
'@' . $a_date);
406 $message =
'Cannot parse date: ' . $a_date .
' with format ' . $a_format;
413 $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);
415 $this->log->write(__METHOD__ .
': Cannot parse date: ' . $a_date);
416 $this->log->write(__METHOD__ .
': ' . print_r($matches,
true));
417 $this->log->logStack();
421 $tz_id = ($d_parts[9] ==
'Z')
438 $this->dt_obj =
new DateTime($a_date,
new DateTimeZone(
'UTC'));
440 $this->log->write(__METHOD__ .
': Cannot parse date: ' . $a_date);
459 if (preg_match(
"/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $a_date, $d_parts) ==
false) {
460 $this->log->write(__METHOD__ .
': Cannot parse date: ' . $a_date);
475 $this->dt_obj = DateTime::createFromFormat(
496 public function get($a_format, $a_format_str =
'', $a_tz =
'')
506 $this->log->write(__METHOD__ .
': Invalid timezone given. Timezone: ' . $a_tz);
512 $out_date = clone($this->dt_obj);
513 $out_date->setTimezone(
new DateTimeZone(
$timezone->getIdentifier()));
522 $date = $out_date->format(
'Y-m-d');
526 $date = $out_date->format(
'Y-m-d H:i:s');
530 $date = $out_date->format($a_format_str);
535 'seconds' => (
int) $out_date->format(
's')
536 ,
'minutes' => (int) $out_date->format(
'i')
537 ,
'hours' => (int) $out_date->format(
'G')
538 ,
'mday' => (int) $out_date->format(
'j')
539 ,
'wday' => (int) $out_date->format(
'w')
540 ,
'mon' => (int) $out_date->format(
'n')
541 ,
'year' => (int) $out_date->format(
'Y')
542 ,
'yday' => (int) $out_date->format(
'z')
543 ,
'weekday' => $out_date->format(
'l')
544 ,
'month' => $out_date->format(
'F')
545 ,
'isoday' => (int) $out_date->format(
'N')
550 $date = $out_date->format(
'c');
554 $date = $out_date->format(
'YmdHis');
__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.
catch(Exception $e) $message
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
Create styles array
The data for the language used.
static _getInstance($a_tz='')
get instance by timezone
getUnixTime()
get unix time
setDate($a_date, $a_format)
Set date.
parsePartsToDate($a_year, $a_month, $a_day, $a_hour=null, $a_min=null, $a_sec=null, $a_timezone=null)
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,...)