ILIAS  release_7 Revision v7.30-3-g800a261c036
ilDateTime Class Reference

@classDescription Date and time handling More...

+ Inheritance diagram for ilDateTime:
+ Collaboration diagram for ilDateTime:

Public Member Functions

 __construct ($a_date=null, $a_format=0, $a_tz='')
 Create new date object. More...
 
 __clone ()
 
 __sleep ()
 
 __wakeup ()
 
 isNull ()
 Check if a date is null (Datetime == '0000-00-00 00:00:00', unixtime == 0,...) More...
 
 switchTimeZone ($a_timezone_identifier='')
 Switch timezone. More...
 
 getTimeZoneIdentifier ()
 get timezone identifier More...
 
 increment ($a_type, $a_count=1)
 increment More...
 
 getUnixTime ()
 get unix time More...
 
 getUTCOffset ()
 get UTC offset More...
 
 setDate ($a_date, $a_format)
 Set date. More...
 
 get ($a_format, $a_format_str='', $a_tz='')
 get formatted date More...
 
 __toString ()
 to string for date time objects Output is user time zone More...
 

Static Public Member Functions

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. More...
 
static _equals (ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
 Check if two date are equal. More...
 
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. More...
 
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. More...
 

Data Fields

const YEAR = 'year'
 
const MONTH = 'month'
 
const WEEK = 'week'
 
const DAY = 'day'
 
const HOUR = 'hour'
 
const MINUTE = 'minute'
 
const SECOND = 'second'
 

Protected Member Functions

 parsePartsToDate ($a_year, $a_month, $a_day, $a_hour=null, $a_min=null, $a_sec=null, $a_timezone=null)
 

Protected Attributes

 $log
 
 $timezone = null
 
 $default_timezone = null
 
 $dt_obj
 

Detailed Description

@classDescription Date and time handling

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 33 of file class.ilDateTime.php.

Constructor & Destructor Documentation

◆ __construct()

ilDateTime::__construct (   $a_date = null,
  $a_format = 0,
  $a_tz = '' 
)

Create new date object.

@access public

Parameters
mixedinteger string following the format given as the second parameter
intformat of date presentation

throws ilDateTimeException

Definition at line 68 of file class.ilDateTime.php.

69 {
70 global $DIC;
71
72 $this->log = $DIC->logger()->cal();
73
74 try {
75 $this->timezone = ilTimeZone::_getInstance($a_tz);
76 $this->default_timezone = ilTimeZone::_getInstance('');
77
78 $this->setDate($a_date, $a_format);
79 } catch (ilTimeZoneException $exc) {
80 $this->log->warning($exc->getMessage());
81 throw new ilDateTimeException('Unsupported timezone given. Timezone: ' . $a_tz);
82 }
83 }
Class for DateTime exceptions.
setDate($a_date, $a_format)
Set date.
Class for TimeZone exceptions.
static _getInstance($a_tz='')
get instance by timezone
global $DIC
Definition: goto.php:24

References $DIC, ilTimeZone\_getInstance(), and setDate().

+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

ilDateTime::__clone ( )

Definition at line 85 of file class.ilDateTime.php.

86 {
87 if ($this->dt_obj) {
88 $this->dt_obj = clone $this->dt_obj;
89 }
90 }

References $dt_obj.

◆ __sleep()

ilDateTime::__sleep ( )

Definition at line 92 of file class.ilDateTime.php.

93 {
94 return array('timezone', 'default_timezone', 'dt_obj');
95 }

◆ __toString()

ilDateTime::__toString ( )

to string for date time objects Output is user time zone

@access public

Parameters

return

Reimplemented in ilDate.

Definition at line 579 of file class.ilDateTime.php.

580 {
581 return $this->get(IL_CAL_DATETIME) . '<br>';
582 }
const IL_CAL_DATETIME

References IL_CAL_DATETIME.

◆ __wakeup()

ilDateTime::__wakeup ( )

Definition at line 97 of file class.ilDateTime.php.

98 {
99 global $DIC;
100
101 $this->log = $DIC->logger()->cal();
102 }

References $DIC.

◆ _after()

static ilDateTime::_after ( ilDateTime  $start,
ilDateTime  $end,
  $a_compare_field = '',
  $a_tz = '' 
)
static

compare two dates and check start is after end This method does not consider tz offsets.

So you have to take care that both dates are defined in the the same timezone

@access public

Parameters
objectilDateTime
objectilDateTime
stringfield used for comparison. E.g IL_CAL_YEAR checks if start is one or more years after than end
stringtimezone

Definition at line 227 of file class.ilDateTime.php.

228 {
229 if ($start->isNull() || $end->isNull()) {
230 return false;
231 }
232
233 switch ($a_compare_field) {
234 case IL_CAL_YEAR:
235 return $start->get(IL_CAL_FKT_DATE, 'Y', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Y', $a_tz);
236
237 case IL_CAL_MONTH:
238 return (int) $start->get(IL_CAL_FKT_DATE, 'Ym', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Ym', $a_tz);
239
240 case IL_CAL_DAY:
241 return (int) $start->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz);
242
243 case '':
244 default:
245 return $start->dt_obj > $end->dt_obj;
246
247 }
248 }
const IL_CAL_YEAR
const IL_CAL_MONTH
const IL_CAL_FKT_DATE
const IL_CAL_DAY
get($a_format, $a_format_str='', $a_tz='')
get formatted date
isNull()
Check if a date is null (Datetime == '0000-00-00 00:00:00', unixtime == 0,...)

References get(), IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_MONTH, IL_CAL_YEAR, and isNull().

Referenced by ilObjGroupAccess\_registrationEnabled(), _within(), ilCalendarRecurrenceCalculator\applyDurationPeriod(), ilCalendarRecurrenceCalculator\applyLimits(), ilCalendarRecurrenceCalculator\calculateDateList(), ilDateDurationInputGUI\checkInput(), ilAppointmentPresentationConsultationHoursGUI\collectPropertiesAndActions(), ilCourseRegistrationGUI\fillRegistrationPeriod(), ilGroupRegistrationGUI\fillRegistrationPeriod(), ilConsultationHourBookingTableGUI\fillRow(), ilSessionClassificationPathGUI\findSessionContainerForItem(), ilPageObject\getActive(), ilCalendarAppointmentPanelGUI\getHTML(), ilCalendarAgendaListGUI\getHTML(), ilBookingEntry\isAppointmentBookableForUser(), ilECSCategoryMappingRule\matchesValue(), ilObjGroup\register(), ilObjectActivationGUI\update(), ilCourseContentGUI\updateManagedTimings(), ilCourseContentGUI\updatePersonalTimings(), and ilECSCategoryMappingRule\validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _before()

static ilDateTime::_before ( ilDateTime  $start,
ilDateTime  $end,
  $a_compare_field = '',
  $a_tz = '' 
)
static

compare two dates and check start is before end This method does not consider tz offsets.

So you have to take care that both dates are defined in the the same timezone

@access public

Parameters
objectilDateTime
objectilDateTime
stringfield used for comparison. E.g IL_CAL_YEAR checks if start is one or more years earlier than end
stringtimezone
Returns
bool

Definition at line 157 of file class.ilDateTime.php.

158 {
159 if ($start->isNull() || $end->isNull()) {
160 return false;
161 }
162
163 switch ($a_compare_field) {
164 case IL_CAL_YEAR:
165 return $start->get(IL_CAL_FKT_DATE, 'Y', $a_tz) < $end->get(IL_CAL_FKT_DATE, 'Y', $a_tz);
166
167 case IL_CAL_MONTH:
168 return (int) $start->get(IL_CAL_FKT_DATE, 'Ym', $a_tz) < $end->get(IL_CAL_FKT_DATE, 'Ym', $a_tz);
169
170 case IL_CAL_DAY:
171 return (int) $start->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz) < $end->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz);
172
173 case '':
174 default:
175 return $start->dt_obj < $end->dt_obj;
176
177 }
178 }

References get(), IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_MONTH, IL_CAL_YEAR, and isNull().

Referenced by ilObjGroupAccess\_registrationEnabled(), _within(), ilMiniCalendarGUI\addMiniMonth(), ilCalendarBlockGUI\addMiniMonth(), ilCalendarRecurrenceCalculator\applyDurationPeriod(), ilCalendarRecurrenceCalculator\applyLimits(), ilCalendarRecurrenceCalculator\calculateDateList(), ilBookingEntry\cancelBooking(), ilCourseRegistrationGUI\fillRegistrationPeriod(), ilGroupRegistrationGUI\fillRegistrationPeriod(), ilECSServerTableGUI\fillRow(), ilPageObject\getActive(), ilConsultationHourUtils\getConsultationHourLinksForRepositoryObject(), ilCalendarAgendaListGUI\getHTML(), ilCalendarBlockGUI\getHTML(), ilExerciseManagementGUI\handleIndividualDeadlineCallsObject(), ilECSTimePlace\loadFromJson(), ilObjCourseAccess\lookupRegistrationInfo(), ilObjGroupAccess\lookupRegistrationInfo(), ilECSCategoryMappingRule\matchesValue(), ilCalendarRecurrenceCalculator\optimizeEndingTime(), ilCalendarRecurrenceCalculator\optimizeStartingTime(), ilUserQuery\query(), ilObjGroup\register(), ilCalendarPresentationGUI\synchroniseExternalCalendars(), and ilCalendarEntry\validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _equals()

static ilDateTime::_equals ( ilDateTime  $start,
ilDateTime  $end,
  $a_compare_field = '',
  $a_tz = '' 
)
static

Check if two date are equal.

@access public

Parameters
objectilDateTime
objectilDateTime
stringfield used for comparison. E.g IL_CAL_YEAR checks if start is the same years than end
stringtimzone
Returns
bool

Definition at line 192 of file class.ilDateTime.php.

193 {
194 if ($start->isNull() || $end->isNull()) {
195 return false;
196 }
197
198 switch ($a_compare_field) {
199 case IL_CAL_YEAR:
200 return $start->get(IL_CAL_FKT_DATE, 'Y', $a_tz) == $end->get(IL_CAL_FKT_DATE, 'Y', $a_tz);
201
202 case IL_CAL_MONTH:
203 return (int) $start->get(IL_CAL_FKT_DATE, 'Ym', $a_tz) == $end->get(IL_CAL_FKT_DATE, 'Ym', $a_tz);
204
205 case IL_CAL_DAY:
206 return (int) $start->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz) == $end->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz);
207
208 case '':
209 default:
210 return $start->dt_obj == $end->dt_obj;
211
212 }
213 }

References get(), IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_MONTH, IL_CAL_YEAR, and isNull().

Referenced by ilCalendarUtil\_isToday(), _within(), ilMiniCalendarGUI\addMiniMonth(), ilCalendarBlockGUI\addMiniMonth(), ilCalendarRecurrenceCalculator\calculateDateList(), ilCalendarAppointmentGUI\edit(), ilSubItemSelectionTableGUI\fillRow(), ilSessionClassificationPathGUI\findSessionContainerForItem(), ilDatePresentation\formatPeriod(), ilCalendarAgendaListGUI\getHTML(), ilDatePresentation\isToday(), ilDatePresentation\isTomorrow(), ilDatePresentation\isYesterday(), and ilDateList\removeByDAY().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _within()

static ilDateTime::_within ( ilDateTime  $dt,
ilDateTime  $start,
ilDateTime  $end,
  $a_compare_field = '',
  $a_tz = '' 
)
static

Check whether an date is within a date duration given by start and end.

Parameters
ilDateTime$dt
ilDateTime$start
ilDateTime$end
type$a_compare_field
type$a_tz

Definition at line 258 of file class.ilDateTime.php.

259 {
260 return
261 (ilDateTime::_after($dt, $start, $a_compare_field, $a_tz) or ilDateTime::_equals($dt, $start, $a_compare_field, $a_tz)) &&
262 (ilDateTime::_before($dt, $end, $a_compare_field, $a_tz) or ilDateTime::_equals($dt, $end, $a_compare_field, $a_tz));
263 }
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
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.

References _after(), _before(), and _equals().

Referenced by ilCalendarScheduleFilterTimings\addCustomEvents(), ilCalendarScheduleFilterExercise\addCustomEvents(), and ilCalendarHeaderNavigationGUI\getHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get()

ilDateTime::get (   $a_format,
  $a_format_str = '',
  $a_tz = '' 
)

get formatted date

@access public

Parameters
intformat type
stringformat string
stringa specific timezone
Returns
string|int

Reimplemented in ilDate.

Definition at line 506 of file class.ilDateTime.php.

507 {
508 if ($this->isNull()) {
509 return;
510 }
511
512 if ($a_tz) {
513 try {
515 } catch (ilTimeZoneException $exc) {
516 $this->log->warning('Invalid timezone given. Timezone: ' . $a_tz);
517 }
518 } else {
520 }
521
522 $out_date = clone($this->dt_obj);
523 $out_date->setTimezone(new DateTimeZone($timezone->getIdentifier()));
524
525 switch ($a_format) {
526 case IL_CAL_UNIX:
527 // timezone unrelated
528 $date = $this->getUnixTime();
529 break;
530
531 case IL_CAL_DATE:
532 $date = $out_date->format('Y-m-d');
533 break;
534
535 case IL_CAL_DATETIME:
536 $date = $out_date->format('Y-m-d H:i:s');
537 break;
538
539 case IL_CAL_FKT_DATE:
540 $date = $out_date->format($a_format_str);
541 break;
542
544 $date = array(
545 'seconds' => (int) $out_date->format('s')
546 ,'minutes' => (int) $out_date->format('i')
547 ,'hours' => (int) $out_date->format('G')
548 ,'mday' => (int) $out_date->format('j')
549 ,'wday' => (int) $out_date->format('w')
550 ,'mon' => (int) $out_date->format('n')
551 ,'year' => (int) $out_date->format('Y')
552 ,'yday' => (int) $out_date->format('z')
553 ,'weekday' => $out_date->format('l')
554 ,'month' => $out_date->format('F')
555 ,'isoday' => (int) $out_date->format('N')
556 );
557 break;
558
559 case IL_CAL_ISO_8601:
560 $date = $out_date->format('c');
561 break;
562
563 case IL_CAL_TIMESTAMP:
564 $date = $out_date->format('YmdHis');
565 break;
566 }
567
568 return $date;
569 }
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_ISO_8601
const IL_CAL_TIMESTAMP
const IL_CAL_UNIX
getUnixTime()
get unix time

References $default_timezone, $timezone, ilTimeZone\_getInstance(), getUnixTime(), IL_CAL_DATE, IL_CAL_DATETIME, IL_CAL_FKT_DATE, IL_CAL_FKT_GETDATE, IL_CAL_ISO_8601, IL_CAL_TIMESTAMP, IL_CAL_UNIX, and isNull().

Referenced by _after(), _before(), _equals(), ilConsultationHourUtils\findCalendarAppointmentsForBooking(), ilDatePresentation\formatDate(), ilDatePresentation\formatPeriod(), ilCmiXapiDateTime\fromIliasDateTime(), ilCalendarRegistration\getRegisteredUsers(), ilCalendarRecurrenceCalculator\getYearWeekDays(), ilCalendarRegistration\isRegistered(), ilLTIDataConnector\lookupResourcesForAllUsersSinceDate(), ilUtil\period2String(), ilExcel\prepareDateValue(), ilExAssignment\setIndividualDeadline(), ilCalendarRegistration\unregister(), and ilCmiXapiUser\updateFetchedUntilForObjects().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTimeZoneIdentifier()

ilDateTime::getTimeZoneIdentifier ( )

get timezone identifier

@access public

Definition at line 138 of file class.ilDateTime.php.

139 {
140 return $this->timezone->getIdentifier();
141 }

Referenced by parsePartsToDate(), and setDate().

+ Here is the caller graph for this function:

◆ getUnixTime()

ilDateTime::getUnixTime ( )

get unix time

@access public

Definition at line 329 of file class.ilDateTime.php.

330 {
331 if (!$this->isNull()) {
332 return $this->dt_obj->getTimestamp();
333 }
334 }

References isNull().

Referenced by get(), and increment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUTCOffset()

ilDateTime::getUTCOffset ( )

get UTC offset

@access public

Returns
offset to utc in seconds

Definition at line 342 of file class.ilDateTime.php.

343 {
344 if (!$this->isNull()) {
345 // already correct/current timezone?
346 $offset = $this->dt_obj->getOffset();
347
348 // TODO: This is wrong: calculate UTC offset of given date
349 // $offset = mktime(0,0,0,2,1,1970) - gmmktime(0,0,0,2,1,1970);
350 }
351 return $offset;
352 }

References isNull().

+ Here is the call graph for this function:

◆ increment()

ilDateTime::increment (   $a_type,
  $a_count = 1 
)

increment

@access public

Parameters
inttype
intcount

Definition at line 273 of file class.ilDateTime.php.

274 {
275 if ($this->isNull()) {
276 return;
277 }
278
279 $sub = ($a_count < 0);
280 $count_str = abs($a_count);
281
282 switch ($a_type) {
283 case self::YEAR:
284 $count_str .= 'year';
285 break;
286
287 case self::MONTH:
288 $count_str .= 'month';
289 break;
290
291 case self::WEEK:
292 $count_str .= 'week';
293 break;
294
295 case self::DAY:
296 $count_str .= 'day';
297 break;
298
299 case self::HOUR:
300 $count_str .= 'hour';
301 break;
302
303 case self::MINUTE:
304 $count_str .= 'minute';
305 break;
306
307 case self::SECOND:
308 $count_str .= 'second';
309 break;
310 }
311
312 $interval = date_interval_create_from_date_string($count_str);
313 if (!$sub) {
314 $this->dt_obj->add($interval);
315 } else {
316 $this->dt_obj->sub($interval);
317 }
318
319 // ???
320 return $this->getUnixTime();
321 }

References DAY, getUnixTime(), HOUR, isNull(), MINUTE, MONTH, SECOND, WEEK, and YEAR.

Referenced by ilTimingsUser\handleNewMembership(), and ilCalendarSchedule\initPeriod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isNull()

ilDateTime::isNull ( )

Check if a date is null (Datetime == '0000-00-00 00:00:00', unixtime == 0,...)

Returns
bool

Definition at line 109 of file class.ilDateTime.php.

110 {
111 return !($this->dt_obj instanceof DateTime);
112 }

Referenced by _after(), _before(), _equals(), ilDatePresentation\formatDate(), get(), getUnixTime(), getUTCOffset(), increment(), ilObjCourseGUI\infoScreen(), and ilObjGroupGUI\infoScreen().

+ Here is the caller graph for this function:

◆ parsePartsToDate()

ilDateTime::parsePartsToDate (   $a_year,
  $a_month,
  $a_day,
  $a_hour = null,
  $a_min = null,
  $a_sec = null,
  $a_timezone = null 
)
protected

Definition at line 354 of file class.ilDateTime.php.

355 {
356 $a_year = (int) $a_year;
357 $a_month = (int) $a_month;
358 $a_day = (int) $a_day;
359
360 if (!$a_year) {
361 return;
362 }
363
364 try {
365 $a_hour = (int) $a_hour;
366 $a_min = (int) $a_min;
367 $a_sec = (int) $a_sec;
368
369 $format = $a_year . '-' . $a_month . '-' . $a_day;
370
371 if ($a_hour !== null) {
372 $format .= ' ' . (int) $a_hour . ':' . (int) $a_min . ':' . (int) $a_sec;
373
374 // use current timezone if no other given
375 if (!$a_timezone) {
376 $a_timezone = $this->getTimeZoneIdentifier();
377 }
378
379 $date = new DateTime($format, new DateTimeZone($a_timezone));
380 } else {
381 $date = new DateTime($format);
382 }
383 } catch (Exception $ex) {
384 // :TODO: do anything?
385 }
386 return ($date instanceof DateTime)
387 ? $date
388 : null;
389 }
getTimeZoneIdentifier()
get timezone identifier
$format
Definition: metadata.php:218

References $format, and getTimeZoneIdentifier().

Referenced by setDate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDate()

ilDateTime::setDate (   $a_date,
  $a_format 
)

Set date.

@access public

Parameters
mixeddate
intformat
Exceptions
ilDateTimeException

Definition at line 401 of file class.ilDateTime.php.

402 {
403 $this->dt_obj = null;
404
405 if (!$a_date) {
406 return;
407 }
408
409 switch ($a_format) {
410 case IL_CAL_UNIX:
411 try {
412 $this->dt_obj = new DateTime('@' . $a_date);
413 $this->dt_obj->setTimezone(new DateTimeZone($this->getTimeZoneIdentifier()));
414 } catch (Exception $ex) {
415 $message = 'Cannot parse date: ' . $a_date . ' with format ' . $a_format;
416 $this->log->warning($message);
417 throw new ilDateTimeException($message);
418 }
419 break;
420
421 case IL_CAL_DATETIME:
422 $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);
423 if ($matches < 1) {
424 $this->log->warning('Cannot parse date: ' . $a_date);
425 $this->log->warning(print_r($matches, true));
426 $this->log->logStack(ilLogLevel::WARNING);
427 throw new ilDateTimeException('Cannot parse date: ' . $a_date);
428 }
429
430 $tz_id = ($d_parts[9] == 'Z')
431 ? 'UTC'
432 : $this->getTimeZoneIdentifier();
433 $this->dt_obj = $this->parsePartsToDate(
434 $d_parts[1],
435 $d_parts[2],
436 $d_parts[3],
437 $d_parts[5],
438 $d_parts[6],
439 $d_parts[7],
440 $tz_id
441 );
442 break;
443
444 case IL_CAL_DATE:
445 try {
446 // Pure dates are not timezone sensible.
447 $this->dt_obj = new DateTime($a_date, new DateTimeZone('UTC'));
448 } catch (Exception $ex) {
449 $this->log->warning('Cannot parse date : ' . $a_date);
450 throw new ilDateTimeException('Cannot parse date: ' . $a_date);
451 }
452 break;
453
455 // Format like getdate parameters
456 $this->dt_obj = $this->parsePartsToDate(
457 $a_date['year'],
458 $a_date['mon'],
459 $a_date['mday'],
460 $a_date['hours'],
461 $a_date['minutes'],
462 $a_date['seconds'],
463 $this->getTimeZoneIdentifier()
464 );
465 break;
466
467 case IL_CAL_TIMESTAMP:
468 if (preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $a_date, $d_parts) == false) {
469 $this->log->warning('Cannot parse date: ' . $a_date);
470 throw new ilDateTimeException('Cannot parse date.');
471 }
472 $this->dt_obj = $this->parsePartsToDate(
473 $d_parts[1],
474 $d_parts[2],
475 $d_parts[3],
476 $d_parts[4],
477 $d_parts[5],
478 $d_parts[6],
479 $this->getTimeZoneIdentifier()
480 );
481 break;
482
483 case IL_CAL_ISO_8601:
484 $this->dt_obj = DateTime::createFromFormat(
485 DateTime::ISO8601,
486 $a_date,
487 new DateTimeZone($this->getTimeZoneIdentifier())
488 );
489 break;
490 }
491
492 // remove set timezone since it does not influence the internal date.
493 // the tz must be passed in the moment of the creation of the date object.
494 return true;
495 }
parsePartsToDate($a_year, $a_month, $a_day, $a_hour=null, $a_min=null, $a_sec=null, $a_timezone=null)
$message
Definition: xapiexit.php:14

References $message, getTimeZoneIdentifier(), IL_CAL_DATE, IL_CAL_DATETIME, IL_CAL_FKT_GETDATE, IL_CAL_ISO_8601, IL_CAL_TIMESTAMP, IL_CAL_UNIX, parsePartsToDate(), and ilLogLevel\WARNING.

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ switchTimeZone()

ilDateTime::switchTimeZone (   $a_timezone_identifier = '')

Switch timezone.

@access public

Parameters
stringPHP timezone identifier
Exceptions
ilDateTimeException

Definition at line 121 of file class.ilDateTime.php.

122 {
123 try {
124 $this->timezone = ilTimeZone::_getInstance($a_timezone_identifier);
125 return true;
126 } catch (ilTimeZoneException $e) {
127 $this->log->warning('Unsupported timezone given: ' . $a_timezone_identifier);
128 throw new ilDateTimeException('Unsupported timezone given. Timezone: ' . $a_timezone_identifier);
129 }
130 }

References Vendor\Package\$e, and ilTimeZone\_getInstance().

Referenced by ilCalendarRecurrenceCalculator\adjustTimeZones().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $default_timezone

ilDateTime::$default_timezone = null
protected

Definition at line 49 of file class.ilDateTime.php.

Referenced by get().

◆ $dt_obj

ilDateTime::$dt_obj
protected

Definition at line 54 of file class.ilDateTime.php.

Referenced by __clone().

◆ $log

ilDateTime::$log
protected

Definition at line 46 of file class.ilDateTime.php.

◆ $timezone

ilDateTime::$timezone = null
protected

Definition at line 48 of file class.ilDateTime.php.

Referenced by get().

◆ DAY

◆ HOUR

const ilDateTime::HOUR = 'hour'

Definition at line 39 of file class.ilDateTime.php.

Referenced by ilConsultationHoursGUI\createAppointments(), and increment().

◆ MINUTE

const ilDateTime::MINUTE = 'minute'

◆ MONTH

◆ SECOND

const ilDateTime::SECOND = 'second'

Definition at line 41 of file class.ilDateTime.php.

Referenced by increment().

◆ WEEK

◆ YEAR

const ilDateTime::YEAR = 'year'

The documentation for this class was generated from the following file: