ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarUtil.php
Go to the documentation of this file.
1<?php
2
24{
25 private static ?ilDateTime $today = null;
26 private static array $default_calendar = array();
27 public static string $init_done;
28 protected static bool $init_datetimepicker = false;
29
30 public static function convertDateToUtcDBTimestamp(?\ilDateTime $date = null): ?string
31 {
32 if (is_null($date)) {
33 return null;
34 }
35 if ($date instanceof \ilDate) {
36 return $date->get(IL_CAL_DATE);
37 }
38 return $date->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
39 }
40
41 public static function _isToday(ilDateTime $date): bool
42 {
43 global $DIC;
44
45 $ilUser = $DIC['ilUser'];
46 if (!is_object(self::$today)) {
47 self::$today = new ilDateTime(time(), IL_CAL_UNIX, $ilUser->getTimeZone());
48 }
49 return ilDateTime::_equals(self::$today, $date, IL_CAL_DAY, $ilUser->getTimeZone());
50 }
51
57 public static function _numericMonthToString(int $a_month, bool $a_long = true, ?ilLanguage $lng = null): string
58 {
59 global $DIC;
60
61 if (is_null($lng)) {
62 $lng = $DIC['lng'];
63 }
64 $month = $a_month < 10 ? '0' . $a_month : $a_month;
65 return $a_long ? $lng->txt('month_' . $month . '_long') : $lng->txt('month_' . $month . '_short');
66 }
67
72 public static function _numericDayToString(int $a_day, bool $a_long = true, ?ilLanguage $lng = null): string
73 {
74 global $DIC;
75
76 if (is_null($lng)) {
77 $lng = $DIC['lng'];
78 }
79 $lng->loadLanguageModule('dateplaner');
80 static $days = array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su');
81
82 return $a_long ? $lng->txt($days[$a_day] . '_long') : $lng->txt($days[$a_day] . '_short');
83 }
84
92 public static function _buildWeekDayList(ilDate $a_day, int $a_weekstart): ilDateList
93 {
94 $day_list = new ilDateList(ilDateList::TYPE_DATE);
95
96 $start = clone $a_day;
97 $start_info = $start->get(IL_CAL_FKT_GETDATE, '', 'UTC');
98 $day_diff = $a_weekstart - $start_info['isoday'];
99 if (abs($day_diff) === 7) {
100 $day_diff = 0;
101 }
102 $start->increment(IL_CAL_DAY, $day_diff);
103 $day_list->add($start);
104 for ($i = 1; $i < 7; $i++) {
105 $start->increment(IL_CAL_DAY, 1);
106 $day_list->add($start);
107 }
108 return $day_list;
109 }
110
118 public static function _buildMonthDayList(int $a_month, int $a_year, int $weekstart): ilDateList
119 {
120 $day_list = new ilDateList(ilDateList::TYPE_DATE);
121
122 $prev_month = ($a_month == 1) ? 12 : $a_month - 1;
123 $prev_year = ($prev_month == 12) ? $a_year - 1 : $a_year;
124 $next_month = $a_month == 12 ? 1 : $a_month + 1;
125 $next_year = $a_month == 12 ? $a_year + 1 : $a_year;
126
127 $days_in_month = self::_getMaxDayOfMonth($a_year, $a_month);
128 $days_in_prev_month = self::_getMaxDayOfMonth($a_year, $prev_month);
129
130 $week_day['year'] = $a_year;
131 $week_day['mon'] = $a_month;
132 $week_day['mday'] = 1;
133 $week_day['hours'] = 0;
134 $week_day['minutes'] = 0;
135 $week_day = new ilDate($week_day, IL_CAL_FKT_GETDATE);
136
137 $weekday = $week_day->get(IL_CAL_FKT_DATE, 'w');
138 $first_day_offset = (($weekday - $weekstart) < 0) ? 6 : $weekday - $weekstart;
139
140 for ($i = 0; $i < 42; $i++) {
141 if ($i < $first_day_offset) {
142 $day = $days_in_prev_month - $first_day_offset + $i + 1;
143
144 $day_list->add(new ilDate(
145 gmmktime(
146 0,
147 0,
148 0,
149 $prev_month,
150 $days_in_prev_month - $first_day_offset + $i + 1,
151 $prev_year
152 ),
154 ));
155 } elseif ($i < $days_in_month + $first_day_offset) {
156 $day = $i - $first_day_offset + 1;
157
158 $day_list->add(new ilDate(
159 gmmktime(
160 0,
161 0,
162 0,
163 $a_month,
164 $i - $first_day_offset + 1,
165 $a_year
166 ),
168 ));
169 } else {
170 $day = $i - $days_in_month - $first_day_offset + 1;
171 $day_list->add(new ilDate(
172 gmmktime(
173 0,
174 0,
175 0,
176 $next_month,
177 $i - $days_in_month - $first_day_offset + 1,
178 $next_year
179 ),
181 ));
182 }
183 if ($i == 34 and ($day < 15 or $day == $days_in_month)) {
184 break;
185 }
186 }
187 return $day_list;
188 }
189
190 public static function initJSCalendar(): void
191 {
192 global $DIC;
193
194 $tpl = $DIC['tpl'];
195 $lng = $DIC['lng'];
196
197 if (self::$init_done == "done") {
198 return;
199 }
200
201 $lng->loadLanguageModule("jscalendar");
202 $tpl->addBlockFile(
203 "CALENDAR_LANG_JAVASCRIPT",
204 "calendar_javascript",
205 "tpl.calendar.html",
206 "components/ILIAS/Calendar"
207 );
208 $tpl->setCurrentBlock("calendar_javascript");
209 $tpl->setVariable("FULL_SUNDAY", $lng->txt("l_su"));
210 $tpl->setVariable("FULL_MONDAY", $lng->txt("l_mo"));
211 $tpl->setVariable("FULL_TUESDAY", $lng->txt("l_tu"));
212 $tpl->setVariable("FULL_WEDNESDAY", $lng->txt("l_we"));
213 $tpl->setVariable("FULL_THURSDAY", $lng->txt("l_th"));
214 $tpl->setVariable("FULL_FRIDAY", $lng->txt("l_fr"));
215 $tpl->setVariable("FULL_SATURDAY", $lng->txt("l_sa"));
216 $tpl->setVariable("SHORT_SUNDAY", $lng->txt("s_su"));
217 $tpl->setVariable("SHORT_MONDAY", $lng->txt("s_mo"));
218 $tpl->setVariable("SHORT_TUESDAY", $lng->txt("s_tu"));
219 $tpl->setVariable("SHORT_WEDNESDAY", $lng->txt("s_we"));
220 $tpl->setVariable("SHORT_THURSDAY", $lng->txt("s_th"));
221 $tpl->setVariable("SHORT_FRIDAY", $lng->txt("s_fr"));
222 $tpl->setVariable("SHORT_SATURDAY", $lng->txt("s_sa"));
223 $tpl->setVariable("FULL_JANUARY", $lng->txt("l_01"));
224 $tpl->setVariable("FULL_FEBRUARY", $lng->txt("l_02"));
225 $tpl->setVariable("FULL_MARCH", $lng->txt("l_03"));
226 $tpl->setVariable("FULL_APRIL", $lng->txt("l_04"));
227 $tpl->setVariable("FULL_MAY", $lng->txt("l_05"));
228 $tpl->setVariable("FULL_JUNE", $lng->txt("l_06"));
229 $tpl->setVariable("FULL_JULY", $lng->txt("l_07"));
230 $tpl->setVariable("FULL_AUGUST", $lng->txt("l_08"));
231 $tpl->setVariable("FULL_SEPTEMBER", $lng->txt("l_09"));
232 $tpl->setVariable("FULL_OCTOBER", $lng->txt("l_10"));
233 $tpl->setVariable("FULL_NOVEMBER", $lng->txt("l_11"));
234 $tpl->setVariable("FULL_DECEMBER", $lng->txt("l_12"));
235 $tpl->setVariable("SHORT_JANUARY", $lng->txt("s_01"));
236 $tpl->setVariable("SHORT_FEBRUARY", $lng->txt("s_02"));
237 $tpl->setVariable("SHORT_MARCH", $lng->txt("s_03"));
238 $tpl->setVariable("SHORT_APRIL", $lng->txt("s_04"));
239 $tpl->setVariable("SHORT_MAY", $lng->txt("s_05"));
240 $tpl->setVariable("SHORT_JUNE", $lng->txt("s_06"));
241 $tpl->setVariable("SHORT_JULY", $lng->txt("s_07"));
242 $tpl->setVariable("SHORT_AUGUST", $lng->txt("s_08"));
243 $tpl->setVariable("SHORT_SEPTEMBER", $lng->txt("s_09"));
244 $tpl->setVariable("SHORT_OCTOBER", $lng->txt("s_10"));
245 $tpl->setVariable("SHORT_NOVEMBER", $lng->txt("s_11"));
246 $tpl->setVariable("SHORT_DECEMBER", $lng->txt("s_12"));
247 $tpl->setVariable("ABOUT_CALENDAR", $lng->txt("about_calendar"));
248 $tpl->setVariable("ABOUT_CALENDAR_LONG", $lng->txt("about_calendar_long"));
249 $tpl->setVariable("ABOUT_TIME_LONG", $lng->txt("about_time"));
250 $tpl->setVariable("PREV_YEAR", $lng->txt("prev_year"));
251 $tpl->setVariable("PREV_MONTH", $lng->txt("prev_month"));
252 $tpl->setVariable("GO_TODAY", $lng->txt("go_today"));
253 $tpl->setVariable("NEXT_MONTH", $lng->txt("next_month"));
254 $tpl->setVariable("NEXT_YEAR", $lng->txt("next_year"));
255 $tpl->setVariable("SEL_DATE", $lng->txt("select_date"));
256 $tpl->setVariable("DRAG_TO_MOVE", $lng->txt("drag_to_move"));
257 $tpl->setVariable("PART_TODAY", $lng->txt("part_today"));
258 $tpl->setVariable("DAY_FIRST", $lng->txt("day_first"));
259 $tpl->setVariable("CLOSE", $lng->txt("close"));
260 $tpl->setVariable("TODAY", $lng->txt("today"));
261 $tpl->setVariable("TIME_PART", $lng->txt("time_part"));
262 $tpl->setVariable("DEF_DATE_FORMAT", $lng->txt("def_date_format"));
263 $tpl->setVariable("TT_DATE_FORMAT", $lng->txt("tt_date_format"));
264 $tpl->setVariable("WK", $lng->txt("wk"));
265 $tpl->setVariable("TIME", $lng->txt("time"));
266 $tpl->parseCurrentBlock();
267 $tpl->setCurrentBlock("CalendarJS");
268 $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR", "./components/ILIAS/Calendar/js/calendar.js");
269 $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_SETUP", "./components/ILIAS/Calendar/js/calendar-setup.js");
270 $tpl->parseCurrentBlock();
271
272 self::$init_done = "done";
273 }
274
275 public static function getZoneInfoFile($a_tz): string
276 {
277 if (!array_key_exists($a_tz, self::_getShortTimeZoneList())) {
278 return '';
279 }
280 $timezone_filename = str_replace('/', '_', $a_tz);
281 $timezone_filename .= '.ics';
282 return '../components/ILIAS/Calendar/zoneinfo/' . $timezone_filename;
283 }
284
288 public static function _getShortTimeZoneList(): array
289 {
290 return array(
291 'Pacific/Samoa' => 'GMT-11: Midway Islands, Samoa',
292 'US/Hawaii' => 'GMT-10:00: Hawaii, Polynesia',
293 'US/Alaska' => 'GMT-9:00: Alaska',
294 'America/Los_Angeles' => 'GMT-8:00: Tijuana, Los Angeles, Seattle, Vancouver',
295 'US/Arizona' => 'GMT-7:00: Arizona',
296 'America/Chihuahua' => 'GMT-7:00: Chihuahua, La Paz, Mazatlan',
297 'America/Denver' => 'GMT-7:00: Arizona, Denver, Salt Lake City, Calgary',
298 'America/Chicago' => 'GMT-6:00: Chicago, Dallas, Kansas City, Winnipeg',
299 'America/Monterrey' => 'GMT-6:00: Guadalajara, Mexico City, Monterrey',
300 'Canada/Saskatchewan' => 'GMT-6:00: Saskatchewan',
301 'US/Central' => 'GMT-6:00: Central America',
302 'America/Bogota' => 'GMT-5:00: Bogota, Lima, Quito',
303 'US/East-Indiana' => 'GMT-5:00: East-Indiana',
304 'America/New_York' => 'GMT-5:00: New York, Miami, Atlanta, Detroit, Toronto',
305 'Canada/Atlantic' => 'GMT-4:00: Atlantic (Canada)',
306 'America/La_Paz' => 'GMT-4:00: Carcas, La Paz',
307 'America/Santiago' => 'GMT-4:00: Santiago',
308 'Canada/Newfoundland' => 'GMT-3:00: Newfoundland',
309 'Brazil/East' => 'GMT-3:00: Sao Paulo',
310 'America/Argentina/Buenos_Aires' => 'GMT-3:00: Buenes Aires, Georgtown',
311 'Etc/GMT+3' => 'GMT-3:00: Greenland, Uruguay, Surinam',
312 'Atlantic/Cape_Verde' => 'GMT-2:00: Cape Verde, Greenland, South Georgia',
313 'Atlantic/Azores' => 'GMT-1:00: Azores',
314 'Africa/Casablanca' => 'GMT+0:00: Casablanca, Monrovia',
315 'Europe/London' => 'GMT+0:00: Dublin, Edinburgh, Lisbon, London',
316 'Europe/Berlin' => 'GMT+1:00: Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
317 'Europe/Belgrade' => 'GMT+1:00: Belgrade, Bratislava, Budapest, Ljubljana, Prague',
318 'Europe/Paris' => 'GMT+1:00: Brussels, Copenhagen, Paris, Madrid',
319 'Europe/Sarajevo' => 'GMT+1:00: Sarajevo, Skopje, Warsaw, Zagreb',
320 'Africa/Lagos' => 'GMT+1:00: West-Central Africa',
321 'Europe/Athens' => 'GMT+2:00: Athens, Beirut, Istanbul, Minsk',
322 'Europe/Bucharest' => 'GMT+2:00: Bucharest',
323 'Africa/Harare' => 'GMT+2:00: Harare, Pratoria',
324 'Europe/Helsinki' => 'GMT+2:00: Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius',
325 'Asia/Jerusalem' => 'GMT+2:00: Jerusalem',
326 'Africa/Cairo' => 'GMT+2:00: Cairo',
327 'Asia/Baghdad' => 'GMT+3:00: Baghdad',
328 'Asia/Kuwait' => 'GMT+3:00: Kuwait, Riyadh',
329 'Europe/Moscow' => 'GMT+3:00: Moscow, Saint Petersburg',
330 'Africa/Nairobi' => 'GMT+3:00: Nairobi',
331 'Asia/Tehran' => 'GMT+3:30: Tehran',
332 'Asia/Muscat' => 'GMT+4:00: Abu Dhabi, Muscat',
333 'Asia/Baku' => 'GMT+4:00: Baku, Tbilisi, Erivan',
334 'Asia/Kabul' => 'GMT+4:00: Kabul',
335 'Asia/Karachi' => 'GMT+5:00: Islamabad, Karachi, Taschkent',
336 'Asia/Yekaterinburg' => 'GMT+5:00: Yekaterinburg',
337 'Asia/Calcutta' => 'GMT+5:30: New Dehli',
338 'Asia/Katmandu' => 'GMT+5:45: Katmandu',
339 'Asia/Novosibirsk' => 'GMT+6:00: Almaty, Novosibirsk',
340 'Asia/Dhaka' => 'GMT+6:00: Astana, Dhaka',
341 'Asia/Rangoon' => 'GMT+6:00: Sri Jayawardenepura, Rangoon',
342 'Asia/Jakarta' => 'GMT+7:00: Bangkok, Hanoi, Jakarta',
343 'Asia/Krasnoyarsk' => 'GMT+7:00: Krasnoyarsk',
344 'Asia/Irkutsk' => 'GMT+8:00: Irkutsk, Ulan Bator',
345 'Asia/Singapore' => 'GMT+8:00: Kuala Lumpour, Singapore',
346 'Asia/Hong_Kong' => 'GMT+8:00: Beijing, Chongqing, Hong kong, Urumchi',
347 'Australia/Perth' => 'GMT+8:00: Perth',
348 'Asia/Taipei' => 'GMT+8:00: Taipei',
349 'Asia/Yakutsk' => 'GMT+9:00: Yakutsk',
350 'Asia/Tokyo' => 'GMT+9:00: Osaka, Sapporo, Tokyo',
351 'Asia/Seoul' => 'GMT+9:00: Seoul, Darwin, Adelaide',
352 'Australia/Brisbane' => 'GMT+10:00: Brisbane',
353 'Australia/Sydney' => 'GMT+10:00: Canberra, Melbourne, Sydney',
354 'Pacific/Guam' => 'GMT+10:00: Guam, Port Moresby',
355 'Australia/Hobart' => 'GMT+10:00: Hobart',
356 'Asia/Vladivostok' => 'GMT+10:00: Vladivostok',
357 'Asia/Magadan' => 'GMT+11:00: Salomon Islands, New Caledonia, Magadan',
358 'Pacific/Auckland' => 'GMT+12:00: Auckland, Wellington',
359 'Pacific/Fiji' => 'GMT+12:00: Fiji, Kamchatka, Marshall-Islands'
360 );
361 }
362
366 public static function _isLeapYear(int $a_year): bool
367 {
368 $is_leap = false;
369 if ($a_year % 4 == 0) {
370 $is_leap = true;
371 if ($a_year % 100 == 0) {
372 $is_leap = false;
373 if ($a_year % 400) {
374 return true;
375 }
376 }
377 }
378 return $is_leap;
379 }
380
385 public static function _getMaxDayOfMonth(int $a_year, int $a_month): int
386 {
387 if (function_exists('cal_days_in_month')) {
388 return cal_days_in_month(CAL_GREGORIAN, $a_month, $a_year);
389 }
390 return (int) date('t', mktime(0, 0, 0, $a_month, 1, $a_year));
391 }
392
398 public static function calculateFontColor(string $a_html_color_code): string
399 {
400 if (strpos($a_html_color_code, '#') !== 0 or strlen($a_html_color_code) != 7) {
401 return '#000000';
402 }
403
404 // http://en.wikipedia.org/wiki/Luminance_(relative)
405 $lum = round(hexdec(substr($a_html_color_code, 1, 2)) * 0.2126 +
406 hexdec(substr($a_html_color_code, 3, 2)) * 0.7152 +
407 hexdec(substr($a_html_color_code, 5, 2)) * 0.0722);
408 return ($lum <= 128) ? "#FFFFFF" : "#000000";
409 }
410
414 public static function getHourSelection(int $a_format): array
415 {
416 $options = [];
417 switch ($a_format) {
419 for ($i = 0; $i < 24; $i++) {
420 $options[$i] = sprintf('%02d:00', $i);
421 }
422 break;
423
425 for ($i = 0; $i < 24; $i++) {
426 $options[$i] = date('h a', mktime($i, 0, 0, 1, 1, 2000));
427 }
428 break;
429 }
430 return $options;
431 }
432
436 public static function initDefaultCalendarByType(
437 int $a_type_id,
438 int $a_usr_id,
439 string $a_title,
440 bool $a_create = false
442 global $DIC;
443
444 $ilDB = $DIC['ilDB'];
445 if (isset(self::$default_calendar[$a_usr_id]) and isset(self::$default_calendar[$a_usr_id][$a_type_id])) {
446 return self::$default_calendar[$a_usr_id][$a_type_id];
447 }
448
449 $query = "SELECT cat_id FROM cal_categories " .
450 "WHERE obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
451 "AND type = " . $ilDB->quote($a_type_id, 'integer');
452 $res = $ilDB->query($query);
453 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
454 return self::$default_calendar[$a_usr_id][$a_type_id] = new ilCalendarCategory($row->cat_id);
455 }
456
457 if (!$a_create) {
458 return null;
459 }
460
461 // Create default calendar
462 self::$default_calendar[$a_usr_id][$a_type_id] = new ilCalendarCategory();
463 self::$default_calendar[$a_usr_id][$a_type_id]->setType($a_type_id);
464 self::$default_calendar[$a_usr_id][$a_type_id]->setColor(ilCalendarCategory::DEFAULT_COLOR);
465 self::$default_calendar[$a_usr_id][$a_type_id]->setTitle($a_title);
466 self::$default_calendar[$a_usr_id][$a_type_id]->setObjId($a_usr_id);
467 self::$default_calendar[$a_usr_id][$a_type_id]->add();
468
469 return self::$default_calendar[$a_usr_id][$a_type_id];
470 }
471
478 public static function getUserDateFormat(int $a_add_time = 0, bool $a_for_parsing = false): string
479 {
480 global $DIC;
481
482 $ilUser = $DIC['ilUser'];
483
484 $format = (string) $ilUser->getDateFormat();
485
486 if ($a_add_time) {
487 $format .= " " . (($ilUser->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_24)
488 ? "H:i"
489 : "h:ia");
490 if ($a_add_time == 2) {
491 $format .= ":s";
492 }
493 }
494
495 // translate datepicker format to PHP format
496 if (!$a_for_parsing) {
497 $format = str_replace("d", "DD", $format);
498 $format = str_replace("m", "MM", $format);
499 $format = str_replace("i", "mm", $format);
500 $format = str_replace("Y", "YYYY", $format);
501 $format = str_replace("H", "HH", $format);
502 $format = str_replace("h", "hh", $format);
503 $format = str_replace("s", "ss", $format);
504 }
505
506 return $format;
507 }
508
509 public static function initDateTimePicker(): void
510 {
511 global $DIC;
512 $tpl = $DIC->ui()->mainTemplate();
513
514 if (!self::$init_datetimepicker) {
515 //$tpl->addJavaScript("assets/js/moment-with-locales.min.js");
516 // unminified version does not work with jQuery 3.0
517 // https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1684
518 //$tpl->addJavaScript("assets/js/bootstrap-datetimepicker.min.js");
519 $tpl->addJavaScript("assets/js/Form.js"); // see ilPropertyFormGUI
520 self::$init_datetimepicker = true;
521 }
522 }
523
532 public static function parseDateString(string $date, bool $add_time = false, ?string $force_format = null): array
533 {
534 global $DIC;
535
536 $ilUser = $DIC['ilUser'];
537 if (!$force_format) {
538 $out_format = self::getUserDateFormat($add_time, true);
539 } else {
540 $out_format = $force_format;
541 }
542
543 $tmp = date_parse_from_format($out_format, $date);
544 $return_date = null;
545
546 if (!$tmp["error_count"] &&
547 !$tmp["warning_count"]) {
548 $format = $tmp["year"] . "-" .
549 str_pad($tmp["month"], 2, "0", STR_PAD_LEFT) . "-" .
550 str_pad($tmp["day"], 2, "0", STR_PAD_LEFT);
551
552 if ($add_time) {
553 $format .= " " .
554 str_pad($tmp["hour"], 2, "0", STR_PAD_LEFT) . ":" .
555 str_pad($tmp["minute"], 2, "0", STR_PAD_LEFT) . ":" .
556 str_pad($tmp["second"], 2, "0", STR_PAD_LEFT);
557
558 $return_date = new ilDateTime($format, IL_CAL_DATETIME, $ilUser->getTimeZone());
559 } else {
560 $return_date = new ilDate($format, IL_CAL_DATE);
561 }
562 }
563
564 return array(
565 "date" => $return_date
566 ,
567 "warnings" => sizeof($tmp["warnings"])
568 ? $tmp["warnings"]
569 : null
570 ,
571 "errors" => sizeof($tmp["errors"])
572 ? $tmp["errors"]
573 : null
574 );
575 }
576
583 public static function parseIncomingDate($value, bool $add_time = false): ?ilDateTime
584 {
585 // already datetime object?
586 if ($value instanceof ilDateTime) {
587 return $value;
588 } elseif (!trim($value)) {
589 return null;
590 }
591
592 // try user-specific format
593 $parsed = self::parseDateString($value, $add_time);
594 if (is_object($parsed['date'])) {
595 return $parsed['date'];
596 }
597
598 // try the previously used generic format
599 $format = $add_time ? 'Y-m-d H:i:s' : 'Y-m-d';
600 $parsed = self::parseDateString($value, $add_time, $format);
601 if (is_object($parsed['date'])) {
602 return $parsed['date'];
603 }
604
605 // try the formats returned by html native datetime-local/date inputs
606 $format = 'Y-m-d';
607 if ($add_time) {
608 // can be with or without seconds
609 $format .= '\TH:i';
610 }
611 $parsed = self::parseDateString($value, $add_time, $format);
612 if (is_object($parsed['date'])) {
613 return $parsed['date'];
614 }
615
616 return null;
617 }
618}
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_FKT_DATE
const IL_CAL_DAY
Stores calendar categories.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getShortTimeZoneList()
get short timezone list
static getUserDateFormat(int $a_add_time=0, bool $a_for_parsing=false)
Parse current user setting into date/time format.
static calculateFontColor(string $a_html_color_code)
Calculate best font color from html hex color code.
static _numericDayToString(int $a_day, bool $a_long=true, ?ilLanguage $lng=null)
static parseIncomingDate($value, bool $add_time=false)
Try to parse incoming value to date object.
static _buildWeekDayList(ilDate $a_day, int $a_weekstart)
build week day list @access public
static convertDateToUtcDBTimestamp(?\ilDateTime $date=null)
static bool $init_datetimepicker
static _getMaxDayOfMonth(int $a_year, int $a_month)
get max day of month 2008,2 => 29
static getHourSelection(int $a_format)
Get hour selection depending on user specific hour format.
static array $default_calendar
static _buildMonthDayList(int $a_month, int $a_year, int $weekstart)
Build a month day list.
static ilDateTime $today
static _isLeapYear(int $a_year)
check if a given year is a leap year
static parseDateString(string $date, bool $add_time=false, ?string $force_format=null)
Parse (incoming) string to date/time object.
static _numericMonthToString(int $a_month, bool $a_long=true, ?ilLanguage $lng=null)
numeric month to string
static _isToday(ilDateTime $date)
static initDefaultCalendarByType(int $a_type_id, int $a_usr_id, string $a_title, bool $a_create=false)
Init the default calendar for given type and user.
static getZoneInfoFile($a_tz)
static string $init_done
List of dates.
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
Class for single dates.
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
language handling
$res
Definition: ltiservices.php:69
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26