ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilDateTime Class Reference

Date and time handling More...

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

Public Member Functions

 __construct ($a_date=null, int $a_format=0, string $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 (string $a_timezone_identifier='')
 Switch timezone. More...
 
 getTimeZoneIdentifier ()
 
 increment (string $a_type, int $a_count=1)
 
 getUnixTime ()
 
 setDate ($a_date, int $a_format)
 Set date. More...
 
 get (int $a_format, string $a_format_str='', string $a_tz='')
 get formatted date More...
 
 __toString ()
 to string for date time objects Output is user time zone public More...
 

Static Public Member Functions

static _before (ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $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, string $a_compare_field='', string $a_tz='')
 Check if two date are equal. More...
 
static _after (ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $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, string $a_compare_field='', string $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 (int $a_year, int $a_month, int $a_day, ?int $a_hour=null, ?int $a_min=null, ?int $a_sec=null, ?string $a_timezone=null)
 

Protected Attributes

ilLogger $log
 
ilTimeZone $timezone = null
 
ilTimeZone $default_timezone = null
 
DateTime $dt_obj = null
 

Detailed Description

Date and time handling

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

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

Constructor & Destructor Documentation

◆ __construct()

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

Create new date object.

Parameters
int|stringfollowing the format given as the second parameter
intformat
string
Exceptions
ilDateTimeException

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

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

51  {
52  global $DIC;
53 
54  $this->log = $DIC->logger()->cal();
55 
56  try {
57  $this->timezone = ilTimeZone::_getInstance($a_tz);
58  $this->default_timezone = ilTimeZone::_getInstance('');
59  $this->setDate($a_date, $a_format);
60  } catch (ilTimeZoneException $exc) {
61  $this->log->warning($exc->getMessage());
62  throw new ilDateTimeException('Unsupported timezone given. Timezone: ' . $a_tz);
63  }
64  }
static _getInstance(string $a_tz='')
get instance by timezone
setDate($a_date, int $a_format)
Set date.
Class for TimeZone exceptions.
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

ilDateTime::__clone ( )

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

References $dt_obj.

67  {
68  if ($this->dt_obj) {
69  $this->dt_obj = clone $this->dt_obj;
70  }
71  }
DateTime $dt_obj

◆ __sleep()

ilDateTime::__sleep ( )

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

74  {
75  return array('timezone', 'default_timezone', 'dt_obj');
76  }

◆ __toString()

ilDateTime::__toString ( )

to string for date time objects Output is user time zone public

Parameters

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

References IL_CAL_DATETIME.

543  : string
544  {
545  return $this->get(IL_CAL_DATETIME) . '<br>';
546  }
const IL_CAL_DATETIME

◆ __wakeup()

ilDateTime::__wakeup ( )

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

References $DIC.

79  {
80  global $DIC;
81  $this->log = $DIC->logger()->cal();
82  }
global $DIC
Definition: shib_login.php:25

◆ _after()

static ilDateTime::_after ( ilDateTime  $start,
ilDateTime  $end,
string  $a_compare_field = '',
string  $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 public

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

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

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(), ilSearchResult\filter(), ilSessionClassificationPathGUI\findSessionContainerForItem(), ilPageObject\getActive(), ilCalendarAppointmentPanelGUI\getHTML(), ilCalendarAgendaListGUI\getHTML(), ilContainerSessionsContentGUI\initSessionPresentationLimitation(), ilBookingEntry\isAppointmentBookableForUser(), ILIAS\Calendar\ConsultationHours\BookingDataProvider\isFiltered(), ilECSCategoryMappingRule\matchesValue(), ilObjGroup\register(), ilCourseContentGUI\updateManagedTimings(), ilCourseContentGUI\updatePersonalTimings(), and ilECSCategoryMappingRule\validate().

200  : bool {
201  if ($start->isNull() || $end->isNull()) {
202  return false;
203  }
204 
205  switch ($a_compare_field) {
206  case IL_CAL_YEAR:
207  return $start->get(IL_CAL_FKT_DATE, 'Y', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Y', $a_tz);
208 
209  case IL_CAL_MONTH:
210  return (int) $start->get(IL_CAL_FKT_DATE, 'Ym', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Ym', $a_tz);
211 
212  case IL_CAL_DAY:
213  return (int) $start->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz);
214 
215  case '':
216  default:
217  return $start->dt_obj > $end->dt_obj;
218  }
219  }
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
const IL_CAL_MONTH
const IL_CAL_DAY
const IL_CAL_FKT_DATE
isNull()
Check if a date is null (Datetime == &#39;0000-00-00 00:00:00&#39;, unixtime == 0,...)
const IL_CAL_YEAR
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _before()

static ilDateTime::_before ( ilDateTime  $start,
ilDateTime  $end,
string  $a_compare_field = '',
string  $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

Parameters
ilDateTime
ilDateTime
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 124 of file class.ilDateTime.php.

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(), ilSearchResult\filter(), ilPageObject\getActive(), ilConsultationHourUtils\getConsultationHourLinksForRepositoryObject(), ilCalendarAgendaListGUI\getHTML(), ilCalendarBlockGUI\getHTML(), ilExerciseManagementGUI\handleIndividualDeadlineCallsObject(), ilContainerSessionsContentGUI\initSessionPresentationLimitation(), ILIAS\Calendar\ConsultationHours\BookingDataProvider\isFiltered(), ilECSTimePlace\loadFromJson(), ilObjGroupAccess\lookupRegistrationInfo(), ilObjCourseAccess\lookupRegistrationInfo(), ilECSCategoryMappingRule\matchesValue(), ilCalendarRecurrenceCalculator\optimizeEndingTime(), ilCalendarRecurrenceCalculator\optimizeStartingTime(), ilUserQuery\query(), ilObjGroup\register(), ilCalendarMonthGUI\show(), and ilCalendarEntry\validate().

129  : bool {
130  if ($start->isNull() || $end->isNull()) {
131  return false;
132  }
133 
134  switch ($a_compare_field) {
135  case IL_CAL_YEAR:
136  return $start->get(IL_CAL_FKT_DATE, 'Y', $a_tz) < $end->get(IL_CAL_FKT_DATE, 'Y', $a_tz);
137 
138  case IL_CAL_MONTH:
139  return (int) $start->get(IL_CAL_FKT_DATE, 'Ym', $a_tz) < $end->get(IL_CAL_FKT_DATE, 'Ym', $a_tz);
140 
141  case IL_CAL_DAY:
142  return (int) $start->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz) < $end->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz);
143 
144  case '':
145  default:
146  return $start->dt_obj < $end->dt_obj;
147  }
148  }
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
const IL_CAL_MONTH
const IL_CAL_DAY
const IL_CAL_FKT_DATE
isNull()
Check if a date is null (Datetime == &#39;0000-00-00 00:00:00&#39;, unixtime == 0,...)
const IL_CAL_YEAR
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _equals()

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

Check if two date are equal.

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

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

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(), ilDateList\removeByDAY(), ilEmployeeTalkTableGUI\setTalkData(), and ilCalendarMonthGUI\show().

163  : bool {
164  if ($start->isNull() || $end->isNull()) {
165  return false;
166  }
167 
168  switch ($a_compare_field) {
169  case IL_CAL_YEAR:
170  return $start->get(IL_CAL_FKT_DATE, 'Y', $a_tz) == $end->get(IL_CAL_FKT_DATE, 'Y', $a_tz);
171 
172  case IL_CAL_MONTH:
173  return (int) $start->get(IL_CAL_FKT_DATE, 'Ym', $a_tz) == $end->get(IL_CAL_FKT_DATE, 'Ym', $a_tz);
174 
175  case IL_CAL_DAY:
176  return (int) $start->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz) == $end->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz);
177 
178  case '':
179  default:
180  return $start->dt_obj == $end->dt_obj;
181  }
182  }
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
const IL_CAL_MONTH
const IL_CAL_DAY
const IL_CAL_FKT_DATE
isNull()
Check if a date is null (Datetime == &#39;0000-00-00 00:00:00&#39;, unixtime == 0,...)
const IL_CAL_YEAR
+ 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,
string  $a_compare_field = '',
string  $a_tz = '' 
)
static

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

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

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

Referenced by ilCalendarScheduleFilterExercise\addCustomEvents(), ilCalendarScheduleFilterTimings\addCustomEvents(), ilSearchResult\filter(), ilCalendarHeaderNavigationGUI\getHTML(), and ilContainerSessionsContentGUI\initSessionPresentationLimitation().

230  : bool {
231  return
232  (ilDateTime::_after($dt, $start, $a_compare_field, $a_tz) or ilDateTime::_equals(
233  $dt,
234  $start,
235  $a_compare_field,
236  $a_tz
237  )) &&
238  (ilDateTime::_before($dt, $end, $a_compare_field, $a_tz) or ilDateTime::_equals(
239  $dt,
240  $end,
241  $a_compare_field,
242  $a_tz
243  ));
244  }
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get()

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

get formatted date

Returns
string|int|array|null

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

References $default_timezone, ilTimeZone\_getInstance(), ilTimeZone\getIdentifier(), 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, ILIAS\Repository\int(), and isNull().

Referenced by _after(), _before(), _equals(), ilDateList\add(), ILIAS\BookingManager\BookingProcess\BookingProcessManager\bookAvailableObjects(), ilConsultationHourUtils\findCalendarAppointmentsForBooking(), ilDatePresentation\formatDate(), ilDatePresentation\formatPeriod(), ilCmiXapiDateTime\fromIliasDateTime(), ilCalendarSchedule\getByDay(), ilCalendarHeaderNavigationGUI\getHTML(), ilCalendarRegistration\getRegisteredUsers(), ilCalendarRecurrenceCalculator\getYearWeekDays(), ilCalendarRegistration\isRegistered(), ilLTIDataConnector\lookupResourcesForAllUsersSinceDate(), ilCalendarWeekGUI\parseHourInfo(), ilLegacyFormElementsUtil\period2String(), ilExcel\prepareDateValue(), ilChatroomHistoryGUI\renderDateTimeInformation(), ilExAssignment\setIndividualDeadline(), ilCalendarRegistration\unregister(), and ilCmiXapiUser\updateFetchedUntilForObjects().

464  {
465  if ($this->isNull()) {
466  return null;
467  }
468 
470  if ($a_tz) {
471  try {
473  } catch (ilTimeZoneException $exc) {
474  $this->log->warning('Invalid timezone given. Timezone: ' . $a_tz);
475  }
476  }
477  $out_date = clone($this->dt_obj);
478  $out_date->setTimezone(new DateTimeZone($timezone->getIdentifier()));
479 
480  $date = null;
481  switch ($a_format) {
482  case IL_CAL_UNIX:
483  // timezone unrelated
484  $date = $this->getUnixTime();
485  break;
486 
487  case IL_CAL_DATE:
488  $date = $out_date->format('Y-m-d');
489  break;
490 
491  case IL_CAL_DATETIME:
492  $date = $out_date->format('Y-m-d H:i:s');
493  break;
494 
495  case IL_CAL_FKT_DATE:
496  $date = $out_date->format($a_format_str);
497  break;
498 
499  case IL_CAL_FKT_GETDATE:
500  $date = array(
501  'seconds' => (int) $out_date->format('s')
502  ,
503  'minutes' => (int) $out_date->format('i')
504  ,
505  'hours' => (int) $out_date->format('G')
506  ,
507  'mday' => (int) $out_date->format('j')
508  ,
509  'wday' => (int) $out_date->format('w')
510  ,
511  'mon' => (int) $out_date->format('n')
512  ,
513  'year' => (int) $out_date->format('Y')
514  ,
515  'yday' => (int) $out_date->format('z')
516  ,
517  'weekday' => $out_date->format('l')
518  ,
519  'month' => $out_date->format('F')
520  ,
521  'isoday' => (int) $out_date->format('N')
522  );
523  break;
524 
525  case IL_CAL_ISO_8601:
526  $date = $out_date->format('c');
527  break;
528 
529  case IL_CAL_TIMESTAMP:
530  $date = $out_date->format('YmdHis');
531  break;
532  }
533  return $date;
534  }
const IL_CAL_DATETIME
static _getInstance(string $a_tz='')
get instance by timezone
ilTimeZone $timezone
ilTimeZone $default_timezone
const IL_CAL_UNIX
Class for TimeZone exceptions.
const IL_CAL_FKT_DATE
const IL_CAL_ISO_8601
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_TIMESTAMP
isNull()
Check if a date is null (Datetime == &#39;0000-00-00 00:00:00&#39;, unixtime == 0,...)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTimeZoneIdentifier()

ilDateTime::getTimeZoneIdentifier ( )

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

Referenced by parsePartsToDate(), and setDate().

109  : string
110  {
111  return $this->timezone->getIdentifier();
112  }
+ Here is the caller graph for this function:

◆ getUnixTime()

ilDateTime::getUnixTime ( )

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

References isNull().

Referenced by ILIAS\EmployeeTalk\Notification\NotificationHandler\extractFormattedDates(), get(), and increment().

300  : ?int
301  {
302  if (!$this->isNull()) {
303  return $this->dt_obj->getTimestamp();
304  }
305  return null;
306  }
isNull()
Check if a date is null (Datetime == &#39;0000-00-00 00:00:00&#39;, unixtime == 0,...)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ increment()

ilDateTime::increment ( string  $a_type,
int  $a_count = 1 
)
Parameters
string$a_type
int$a_count
Returns
int|null
Todo:
refactor return type

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

References getUnixTime(), and isNull().

Referenced by ilCalendarRecurrenceCalculator\applyBYDAYRules(), ilCalendarSchedule\getByDay(), ilCalendarSchedule\getChangedEvents(), ilTimingsUser\handleNewMembership(), ilCalendarRecurrenceCalculator\incrementByFrequency(), ilCalendarAppointmentGUI\initAppointment(), ilCalendarAgendaListGUI\initEndPeriod(), and ilCalendarSchedule\initPeriod().

252  : ?int
253  {
254  if ($this->isNull()) {
255  return null;
256  }
257 
258  $sub = ($a_count < 0);
259  $count_str = abs($a_count);
260 
261  switch ($a_type) {
262  case self::YEAR:
263  $count_str .= 'year';
264  break;
265 
266  case self::MONTH:
267  $count_str .= 'month';
268  break;
269 
270  case self::WEEK:
271  $count_str .= 'week';
272  break;
273 
274  case self::DAY:
275  $count_str .= 'day';
276  break;
277 
278  case self::HOUR:
279  $count_str .= 'hour';
280  break;
281 
282  case self::MINUTE:
283  $count_str .= 'minute';
284  break;
285 
286  case self::SECOND:
287  $count_str .= 'second';
288  break;
289  }
290 
291  $interval = date_interval_create_from_date_string($count_str);
292  if (!$sub) {
293  $this->dt_obj->add($interval);
294  } else {
295  $this->dt_obj->sub($interval);
296  }
297  return $this->getUnixTime();
298  }
isNull()
Check if a date is null (Datetime == &#39;0000-00-00 00:00:00&#39;, unixtime == 0,...)
+ 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 88 of file class.ilDateTime.php.

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

88  : bool
89  {
90  return !($this->dt_obj instanceof DateTime);
91  }
+ Here is the caller graph for this function:

◆ parsePartsToDate()

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

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

References getTimeZoneIdentifier(), and ILIAS\Repository\int().

Referenced by setDate().

316  : ?DateTime {
317  $a_year = $a_year;
318  $a_month = $a_month;
319  $a_day = $a_day;
320 
321  if (!$a_year) {
322  return null;
323  }
324  $date = null;
325  try {
326  $a_hour = (int) $a_hour;
327  $a_min = (int) $a_min;
328  $a_sec = (int) $a_sec;
329 
330  $format = $a_year . '-' . $a_month . '-' . $a_day;
331 
332  if ($a_hour !== null) {
333  $format .= ' ' . $a_hour . ':' . $a_min . ':' . $a_sec;
334 
335  // use current timezone if no other given
336  if (!$a_timezone) {
337  $a_timezone = $this->getTimeZoneIdentifier();
338  }
339 
340  $date = new DateTime($format, new DateTimeZone($a_timezone));
341  } else {
342  $date = new DateTime($format);
343  }
344  } catch (Exception $ex) {
345  // :TODO: do anything?
346  }
347  return ($date instanceof DateTime)
348  ? $date
349  : null;
350  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDate()

ilDateTime::setDate (   $a_date,
int  $a_format 
)

Set date.

Exceptions
ilDateTimeException
Todo:
fix ISO_8601 support

False "DateTime::ATOM was removed 7.2 warning" is a false positve

PhpElementIsNotAvailableInCurrentPhpVersionInspection

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

References 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(), and ilExAssignmentEditorGUI\setDisabledFieldValues().

357  : void
358  {
359  $this->dt_obj = null;
360 
361  if (!$a_date) {
362  return;
363  }
364 
365  switch ($a_format) {
366  case IL_CAL_UNIX:
367  try {
368  $this->dt_obj = new DateTime('@' . $a_date);
369  $this->dt_obj->setTimezone(new DateTimeZone($this->getTimeZoneIdentifier()));
370  } catch (Exception $ex) {
371  $message = 'Cannot parse date: ' . $a_date . ' with format ' . $a_format;
372  $this->log->warning($message);
373  throw new ilDateTimeException($message);
374  }
375  break;
376 
377  case IL_CAL_DATETIME:
378  $matches = preg_match(
379  '/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)$/i',
380  $a_date,
381  $d_parts
382  );
383  if ($matches < 1) {
384  $this->log->warning('Cannot parse date: ' . $a_date);
385  $this->log->warning(print_r($matches, true));
386  $this->log->logStack(ilLogLevel::WARNING);
387  throw new ilDateTimeException('Cannot parse date: ' . $a_date);
388  }
389 
390  $tz_id = (isset($d_parts[9]) && $d_parts[9] === 'Z')
391  ? 'UTC'
392  : $this->getTimeZoneIdentifier();
393  $this->dt_obj = $this->parsePartsToDate(
394  (int) $d_parts[1],
395  (int) $d_parts[2],
396  (int) $d_parts[3],
397  (int) $d_parts[5],
398  (int) $d_parts[6],
399  (int) $d_parts[7],
400  $tz_id
401  );
402  break;
403 
404  case IL_CAL_DATE:
405  try {
406  // Pure dates are not timezone sensible.
407  $this->dt_obj = new DateTime($a_date, new DateTimeZone('UTC'));
408  } catch (Exception $ex) {
409  $this->log->warning('Cannot parse date : ' . $a_date);
410  throw new ilDateTimeException('Cannot parse date: ' . $a_date);
411  }
412  break;
413 
414  case IL_CAL_FKT_GETDATE:
415  // Format like getdate parameters
416  $this->dt_obj = $this->parsePartsToDate(
417  (int) $a_date['year'],
418  (int) $a_date['mon'],
419  (int) $a_date['mday'],
420  (int) $a_date['hours'],
421  (int) $a_date['minutes'],
422  (int) ($a_date['seconds'] ?? 0),
423  $this->getTimeZoneIdentifier()
424  );
425  break;
426 
427  case IL_CAL_TIMESTAMP:
428  if (!preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $a_date, $d_parts)) {
429  $this->log->warning('Cannot parse date: ' . $a_date);
430  throw new ilDateTimeException('Cannot parse date.');
431  }
432  $this->dt_obj = $this->parsePartsToDate(
433  (int) $d_parts[1],
434  (int) $d_parts[2],
435  (int) $d_parts[3],
436  (int) $d_parts[4],
437  (int) $d_parts[5],
438  (int) $d_parts[6],
439  $this->getTimeZoneIdentifier()
440  );
441  break;
442 
443  case IL_CAL_ISO_8601:
448  $this->dt_obj = DateTime::createFromFormat(
449  DateTime::ATOM,
450  $a_date,
451  new DateTimeZone($this->getTimeZoneIdentifier())
452  );
453  break;
454  }
455  // remove set timezone since it does not influence the internal date.
456  // the tz must be passed in the moment of the creation of the date object.
457  }
const IL_CAL_DATETIME
parsePartsToDate(int $a_year, int $a_month, int $a_day, ?int $a_hour=null, ?int $a_min=null, ?int $a_sec=null, ?string $a_timezone=null)
const IL_CAL_UNIX
const IL_CAL_ISO_8601
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_TIMESTAMP
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ switchTimeZone()

ilDateTime::switchTimeZone ( string  $a_timezone_identifier = '')

Switch timezone.

Parameters
stringPHP timezone identifier
Exceptions
ilDateTimeException

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

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

Referenced by ilCalendarRecurrenceCalculator\adjustTimeZones().

98  : void
99  {
100  try {
101  $this->timezone = ilTimeZone::_getInstance($a_timezone_identifier);
102  return;
103  } catch (ilTimeZoneException $e) {
104  $this->log->warning('Unsupported timezone given: ' . $a_timezone_identifier);
105  throw new ilDateTimeException('Unsupported timezone given. Timezone: ' . $a_timezone_identifier);
106  }
107  }
static _getInstance(string $a_tz='')
get instance by timezone
Class for TimeZone exceptions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $default_timezone

ilTimeZone ilDateTime::$default_timezone = null
protected

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

Referenced by get().

◆ $dt_obj

DateTime ilDateTime::$dt_obj = null
protected

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

Referenced by __clone().

◆ $log

ilLogger ilDateTime::$log
protected

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

◆ $timezone

ilTimeZone ilDateTime::$timezone = null
protected

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

◆ DAY

◆ HOUR

const ilDateTime::HOUR = 'hour'

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

Referenced by ilConsultationHoursGUI\createAppointments().

◆ MINUTE

const ilDateTime::MINUTE = 'minute'

◆ MONTH

◆ SECOND

const ilDateTime::SECOND = 'second'

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

◆ WEEK

◆ YEAR

const ilDateTime::YEAR = 'year'

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