ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCalendarUtil.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
25
34{
35 private static $today = null;
36 private static $default_calendar = array();
37 public static $init_done;
38 protected static $init_datetimepicker;
39
46 public static function _isToday($date)
47 {
48 global $DIC;
49
50 $ilUser = $DIC['ilUser'];
51
52
53 if (!is_object(self::$today)) {
54 self::$today = new ilDateTime(time(), IL_CAL_UNIX, $ilUser->getTimeZone());
55 }
56 return ilDateTime::_equals(self::$today, $date, IL_CAL_DAY, $ilUser->getTimeZone());
57 }
58
68 public static function _numericMonthToString($a_month, $a_long = true)
69 {
70 global $DIC;
71
72 $lng = $DIC['lng'];
73
74 $month = $a_month < 10 ? '0' . $a_month : $a_month;
75
76 return $a_long ? $lng->txt('month_' . $month . '_long') : $lng->txt('month_' . $month . '_short');
77 }
78
88 public static function _numericDayToString($a_day, $a_long = true)
89 {
90 global $DIC;
91
92 $lng = $DIC['lng'];
93
94 $lng->loadLanguageModule('dateplaner');
95 static $days = array('Su','Mo','Tu','We','Th','Fr','Sa','Su');
96
97 return $a_long ? $lng->txt($days[$a_day] . '_long') : $lng->txt($days[$a_day] . '_short');
98 }
99
109 public static function _buildWeekDayList($a_day, $a_weekstart)
110 {
111 include_once('Services/Calendar/classes/class.ilDateList.php');
112 $day_list = new ilDateList(ilDateList::TYPE_DATE);
113
114 $start = clone $a_day;
115 $start_info = $start->get(IL_CAL_FKT_GETDATE, '', 'UTC');
116 $day_diff = $a_weekstart - $start_info['isoday'];
117 if ($day_diff == 7) {
118 $day_diff = 0;
119 }
120 $start->increment(IL_CAL_DAY, $day_diff);
121 $day_list->add($start);
122 for ($i = 1; $i < 7;$i++) {
123 $start->increment(IL_CAL_DAY, 1);
124 $day_list->add($start);
125 }
126 return $day_list;
127 }
128
139 public static function _buildMonthDayList($a_month, $a_year, $weekstart)
140 {
141 include_once('Services/Calendar/classes/class.ilDateList.php');
142 $day_list = new ilDateList(ilDateList::TYPE_DATE);
143
144 $prev_month = ($a_month == 1) ? 12 : $a_month - 1;
145 $prev_year = ($prev_month == 12) ? $a_year - 1 : $a_year;
146 $next_month = $a_month == 12 ? 1 : $a_month + 1;
147 $next_year = $a_month == 12 ? $a_year + 1 : $a_year;
148
149 $days_in_month = self::_getMaxDayOfMonth($a_year, $a_month);
150 $days_in_prev_month = self::_getMaxDayOfMonth($a_year, $prev_month);
151
152 $week_day['year'] = $a_year;
153 $week_day['mon'] = $a_month;
154 $week_day['mday'] = 1;
155 $week_day['hours'] = 0;
156 $week_day['minutes'] = 0;
157 $week_day = new ilDate($week_day, IL_CAL_FKT_GETDATE);
158
159 $weekday = $week_day->get(IL_CAL_FKT_DATE, 'w');
160 $first_day_offset = (($weekday - $weekstart) < 0) ? 6 : $weekday - $weekstart;
161
162
163 for ($i = 0;$i < 42;$i++) {
164 if ($i < $first_day_offset) {
165 $day = $days_in_prev_month - $first_day_offset + $i + 1;
166
167 $day_list->add(new ilDate(
168 gmmktime(
169 0,
170 0,
171 0,
172 $prev_month,
173 $days_in_prev_month - $first_day_offset + $i + 1,
174 $prev_year
175 ),
177 ));
178 } elseif ($i < $days_in_month + $first_day_offset) {
179 $day = $i - $first_day_offset + 1;
180
181
182 $day_list->add(new ilDate(
183 gmmktime(
184 0,
185 0,
186 0,
187 $a_month,
188 $i - $first_day_offset + 1,
189 $a_year
190 ),
192 ));
193 } else {
194 $day = $i - $days_in_month - $first_day_offset + 1;
195 $day_list->add(new ilDate(
196 gmmktime(
197 0,
198 0,
199 0,
200 $next_month,
201 $i - $days_in_month - $first_day_offset + 1,
202 $next_year
203 ),
205 ));
206 }
207 if ($i == 34 and ($day < 15 or $day == $days_in_month)) {
208 break;
209 }
210 }
211 return $day_list;
212 }
213
217 public static function initJSCalendar()
218 {
219 global $DIC;
220
221 $tpl = $DIC['tpl'];
222 $lng = $DIC['lng'];
223
224 if (self::$init_done == "done") {
225 return;
226 }
227
228 $lng->loadLanguageModule("jscalendar");
229 $tpl->addBlockFile(
230 "CALENDAR_LANG_JAVASCRIPT",
231 "calendar_javascript",
232 "tpl.calendar.html",
233 "Services/Calendar"
234 );
235 $tpl->setCurrentBlock("calendar_javascript");
236 $tpl->setVariable("FULL_SUNDAY", $lng->txt("l_su"));
237 $tpl->setVariable("FULL_MONDAY", $lng->txt("l_mo"));
238 $tpl->setVariable("FULL_TUESDAY", $lng->txt("l_tu"));
239 $tpl->setVariable("FULL_WEDNESDAY", $lng->txt("l_we"));
240 $tpl->setVariable("FULL_THURSDAY", $lng->txt("l_th"));
241 $tpl->setVariable("FULL_FRIDAY", $lng->txt("l_fr"));
242 $tpl->setVariable("FULL_SATURDAY", $lng->txt("l_sa"));
243 $tpl->setVariable("SHORT_SUNDAY", $lng->txt("s_su"));
244 $tpl->setVariable("SHORT_MONDAY", $lng->txt("s_mo"));
245 $tpl->setVariable("SHORT_TUESDAY", $lng->txt("s_tu"));
246 $tpl->setVariable("SHORT_WEDNESDAY", $lng->txt("s_we"));
247 $tpl->setVariable("SHORT_THURSDAY", $lng->txt("s_th"));
248 $tpl->setVariable("SHORT_FRIDAY", $lng->txt("s_fr"));
249 $tpl->setVariable("SHORT_SATURDAY", $lng->txt("s_sa"));
250 $tpl->setVariable("FULL_JANUARY", $lng->txt("l_01"));
251 $tpl->setVariable("FULL_FEBRUARY", $lng->txt("l_02"));
252 $tpl->setVariable("FULL_MARCH", $lng->txt("l_03"));
253 $tpl->setVariable("FULL_APRIL", $lng->txt("l_04"));
254 $tpl->setVariable("FULL_MAY", $lng->txt("l_05"));
255 $tpl->setVariable("FULL_JUNE", $lng->txt("l_06"));
256 $tpl->setVariable("FULL_JULY", $lng->txt("l_07"));
257 $tpl->setVariable("FULL_AUGUST", $lng->txt("l_08"));
258 $tpl->setVariable("FULL_SEPTEMBER", $lng->txt("l_09"));
259 $tpl->setVariable("FULL_OCTOBER", $lng->txt("l_10"));
260 $tpl->setVariable("FULL_NOVEMBER", $lng->txt("l_11"));
261 $tpl->setVariable("FULL_DECEMBER", $lng->txt("l_12"));
262 $tpl->setVariable("SHORT_JANUARY", $lng->txt("s_01"));
263 $tpl->setVariable("SHORT_FEBRUARY", $lng->txt("s_02"));
264 $tpl->setVariable("SHORT_MARCH", $lng->txt("s_03"));
265 $tpl->setVariable("SHORT_APRIL", $lng->txt("s_04"));
266 $tpl->setVariable("SHORT_MAY", $lng->txt("s_05"));
267 $tpl->setVariable("SHORT_JUNE", $lng->txt("s_06"));
268 $tpl->setVariable("SHORT_JULY", $lng->txt("s_07"));
269 $tpl->setVariable("SHORT_AUGUST", $lng->txt("s_08"));
270 $tpl->setVariable("SHORT_SEPTEMBER", $lng->txt("s_09"));
271 $tpl->setVariable("SHORT_OCTOBER", $lng->txt("s_10"));
272 $tpl->setVariable("SHORT_NOVEMBER", $lng->txt("s_11"));
273 $tpl->setVariable("SHORT_DECEMBER", $lng->txt("s_12"));
274 $tpl->setVariable("ABOUT_CALENDAR", $lng->txt("about_calendar"));
275 $tpl->setVariable("ABOUT_CALENDAR_LONG", $lng->txt("about_calendar_long"));
276 $tpl->setVariable("ABOUT_TIME_LONG", $lng->txt("about_time"));
277 $tpl->setVariable("PREV_YEAR", $lng->txt("prev_year"));
278 $tpl->setVariable("PREV_MONTH", $lng->txt("prev_month"));
279 $tpl->setVariable("GO_TODAY", $lng->txt("go_today"));
280 $tpl->setVariable("NEXT_MONTH", $lng->txt("next_month"));
281 $tpl->setVariable("NEXT_YEAR", $lng->txt("next_year"));
282 $tpl->setVariable("SEL_DATE", $lng->txt("select_date"));
283 $tpl->setVariable("DRAG_TO_MOVE", $lng->txt("drag_to_move"));
284 $tpl->setVariable("PART_TODAY", $lng->txt("part_today"));
285 $tpl->setVariable("DAY_FIRST", $lng->txt("day_first"));
286 $tpl->setVariable("CLOSE", $lng->txt("close"));
287 $tpl->setVariable("TODAY", $lng->txt("today"));
288 $tpl->setVariable("TIME_PART", $lng->txt("time_part"));
289 $tpl->setVariable("DEF_DATE_FORMAT", $lng->txt("def_date_format"));
290 $tpl->setVariable("TT_DATE_FORMAT", $lng->txt("tt_date_format"));
291 $tpl->setVariable("WK", $lng->txt("wk"));
292 $tpl->setVariable("TIME", $lng->txt("time"));
293 $tpl->parseCurrentBlock();
294 $tpl->setCurrentBlock("CalendarJS");
295 $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR", "./Services/Calendar/js/calendar.js");
296 $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_SETUP", "./Services/Calendar/js/calendar-setup.js");
297 $tpl->parseCurrentBlock();
298
299 self::$init_done = "done";
300 }
301
302 public static function getZoneInfoFile($a_tz)
303 {
304 if (!array_key_exists($a_tz, self::_getShortTimeZoneList())) {
305 return '';
306 }
307 $timezone_filename = str_replace('/', '_', $a_tz);
308 $timezone_filename .= '.ics';
309 return './Services/Calendar/zoneinfo/' . $timezone_filename;
310 }
311
312
321 public static function _getShortTimeZoneList()
322 {
323 return array(
324 'Pacific/Samoa' => 'GMT-11: Midway Islands, Samoa',
325 'US/Hawaii' => 'GMT-10:00: Hawaii, Polynesia',
326 'US/Alaska' => 'GMT-9:00: Alaska',
327 'America/Los_Angeles' => 'GMT-8:00: Tijuana, Los Angeles, Seattle, Vancouver',
328 'US/Arizona' => 'GMT-7:00: Arizona',
329 'America/Chihuahua' => 'GMT-7:00: Chihuahua, La Paz, Mazatlan',
330 'America/Denver' => 'GMT-7:00: Arizona, Denver, Salt Lake City, Calgary',
331 'America/Chicago' => 'GMT-6:00: Chicago, Dallas, Kansas City, Winnipeg',
332 'America/Monterrey' => 'GMT-6:00: Guadalajara, Mexico City, Monterrey',
333 'Canada/Saskatchewan' => 'GMT-6:00: Saskatchewan',
334 'US/Central' => 'GMT-6:00: Central America',
335 'America/Bogota' => 'GMT-5:00: Bogota, Lima, Quito',
336 'US/East-Indiana' => 'GMT-5:00: East-Indiana',
337 'America/New_York' => 'GMT-5:00: New York, Miami, Atlanta, Detroit, Toronto',
338 'Canada/Atlantic' => 'GMT-4:00: Atlantic (Canada)',
339 'America/La_Paz' => 'GMT-4:00: Carcas, La Paz',
340 'America/Santiago' => 'GMT-4:00: Santiago',
341 'Canada/Newfoundland' => 'GMT-3:00: Newfoundland',
342 'Brazil/East' => 'GMT-3:00: Sao Paulo',
343 'America/Argentina/Buenos_Aires' => 'GMT-3:00: Buenes Aires, Georgtown',
344 'Etc/GMT+3' => 'GMT-3:00: Greenland, Uruguay, Surinam',
345 'Atlantic/Cape_Verde' => 'GMT-2:00: Cape Verde, Greenland, South Georgia',
346 'Atlantic/Azores' => 'GMT-1:00: Azores',
347 'Africa/Casablanca' => 'GMT+0:00: Casablanca, Monrovia',
348 'Europe/London' => 'GMT+0:00: Dublin, Edinburgh, Lisbon, London',
349 'Europe/Berlin' => 'GMT+1:00: Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
350 'Europe/Belgrade' => 'GMT+1:00: Belgrade, Bratislava, Budapest, Ljubljana, Prague',
351 'Europe/Paris' => 'GMT+1:00: Brussels, Copenhagen, Paris, Madrid',
352 'Europe/Sarajevo' => 'GMT+1:00: Sarajevo, Skopje, Warsaw, Zagreb',
353 'Africa/Lagos' => 'GMT+1:00: West-Central Africa',
354 'Europe/Athens' => 'GMT+2:00: Athens, Beirut, Istanbul, Minsk',
355 'Europe/Bucharest' => 'GMT+2:00: Bucharest',
356 'Africa/Harare' => 'GMT+2:00: Harare, Pratoria',
357 'Europe/Helsinki' => 'GMT+2:00: Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius',
358 'Asia/Jerusalem' => 'GMT+2:00: Jerusalem',
359 'Africa/Cairo' => 'GMT+2:00: Cairo',
360 'Asia/Baghdad' => 'GMT+3:00: Baghdad',
361 'Asia/Kuwait' => 'GMT+3:00: Kuwait, Riyadh',
362 'Europe/Moscow' => 'GMT+3:00: Moscow, Saint Petersburg',
363 'Africa/Nairobi' => 'GMT+3:00: Nairobi',
364 'Asia/Tehran' => 'GMT+3:30: Tehran',
365 'Asia/Muscat' => 'GMT+4:00: Abu Dhabi, Muscat',
366 'Asia/Baku' => 'GMT+4:00: Baku, Tbilisi, Erivan',
367 'Asia/Kabul' => 'GMT+4:00: Kabul',
368 'Asia/Karachi' => 'GMT+5:00: Islamabad, Karachi, Taschkent',
369 'Asia/Yekaterinburg' => 'GMT+5:00: Yekaterinburg',
370 'Asia/Calcutta' => 'GMT+5:30: New Dehli',
371 'Asia/Katmandu' => 'GMT+5:45: Katmandu',
372 'Asia/Novosibirsk' => 'GMT+6:00: Almaty, Novosibirsk',
373 'Asia/Dhaka' => 'GMT+6:00: Astana, Dhaka',
374 'Asia/Rangoon' => 'GMT+6:00: Sri Jayawardenepura, Rangoon',
375 'Asia/Jakarta' => 'GMT+7:00: Bangkok, Hanoi, Jakarta',
376 'Asia/Krasnoyarsk' => 'GMT+7:00: Krasnoyarsk',
377 'Asia/Irkutsk' => 'GMT+8:00: Irkutsk, Ulan Bator',
378 'Asia/Singapore' => 'GMT+8:00: Kuala Lumpour, Singapore',
379 'Asia/Hong_Kong' => 'GMT+8:00: Beijing, Chongqing, Hong kong, Urumchi',
380 'Australia/Perth' => 'GMT+8:00: Perth',
381 'Asia/Taipei' => 'GMT+8:00: Taipei',
382 'Asia/Yakutsk' => 'GMT+9:00: Yakutsk',
383 'Asia/Tokyo' => 'GMT+9:00: Osaka, Sapporo, Tokyo',
384 'Asia/Seoul' => 'GMT+9:00: Seoul, Darwin, Adelaide',
385 'Australia/Brisbane' => 'GMT+10:00: Brisbane',
386 'Australia/Sydney' => 'GMT+10:00: Canberra, Melbourne, Sydney',
387 'Pacific/Guam' => 'GMT+10:00: Guam, Port Moresby',
388 'Australia/Hobart' => 'GMT+10:00: Hobart',
389 'Asia/Vladivostok' => 'GMT+10:00: Vladivostok',
390 'Asia/Magadan' => 'GMT+11:00: Salomon Islands, New Caledonia, Magadan',
391 'Pacific/Auckland' => 'GMT+12:00: Auckland, Wellington',
392 'Pacific/Fiji' => 'GMT+12:00: Fiji, Kamchatka, Marshall-Islands');
393 }
394
395
403 public static function _isLeapYear($a_year)
404 {
405 $is_leap = false;
406
407 if ($a_year % 4 == 0) {
408 $is_leap = true;
409 if ($a_year % 100 == 0) {
410 $is_leap = false;
411 if ($a_year % 400) {
412 return true;
413 }
414 }
415 }
416 return $is_leap;
417 }
418
428 public static function _getMaxDayOfMonth($a_year, $a_month)
429 {
430 if (@function_exists('cal_days_in_month')) {
431 return cal_days_in_month(CAL_GREGORIAN, $a_month, $a_year);
432 }
433 $months = array(0,31,
434 self::_isLeapYear($a_year) ? 29 : 28,
435 31,30,31,30,31,31,30,31,30,31);
436 return $months[(int) $a_month];
437 }
438
447 public static function calculateFontColor($a_html_color_code)
448 {
449 if (strpos($a_html_color_code, '#') !== 0 or strlen($a_html_color_code) != 7) {
450 return '#000000';
451 }
452
453 // http://en.wikipedia.org/wiki/Luminance_(relative)
454 $lum = round(hexdec(substr($a_html_color_code, 1, 2)) * 0.2126 +
455 hexdec(substr($a_html_color_code, 3, 2)) * 0.7152 +
456 hexdec(substr($a_html_color_code, 5, 2)) * 0.0722);
457
458 return ($lum <= 128) ? "#FFFFFF" : "#000000";
459
460 /*
461 $hex = str_replace('#','0x',$a_html_color_code);
462 return hexdec($hex) > 8000000 ? '#000000' : '#FFFFFF';
463 */
464 }
465
471 public static function getHourSelection($a_format)
472 {
473 switch ($a_format) {
475 for ($i = 0; $i < 24; $i++) {
476 $options[$i] = sprintf('%02d:00', $i);
477 }
478 break;
479
481 for ($i = 0; $i < 24; $i++) {
482 $options[$i] = date('h a', mktime($i, 0, 0, 1, 1, 2000));
483 }
484 break;
485 }
486 return $options ? $options : array();
487 }
488
497 public static function initDefaultCalendarByType($a_type_id, $a_usr_id, $a_title, $a_create = false)
498 {
499 global $DIC;
500
501 $ilDB = $DIC['ilDB'];
502
503 if (isset(self::$default_calendar[$a_usr_id]) and isset(self::$default_calendar[$a_usr_id][$a_type_id])) {
504 return self::$default_calendar[$a_usr_id][$a_type_id];
505 }
506
507 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
508
509 $query = "SELECT cat_id FROM cal_categories " .
510 "WHERE obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
511 "AND type = " . $ilDB->quote($a_type_id, 'integer');
512 $res = $ilDB->query($query);
513 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
514 return self::$default_calendar[$a_usr_id][$a_type_id] = new ilCalendarCategory($row->cat_id);
515 }
516
517 if (!$a_create) {
518 return null;
519 }
520
521 // Create default calendar
522 self::$default_calendar[$a_usr_id][$a_type_id] = new ilCalendarCategory();
523 self::$default_calendar[$a_usr_id][$a_type_id]->setType($a_type_id);
524 self::$default_calendar[$a_usr_id][$a_type_id]->setColor(ilCalendarCategory::DEFAULT_COLOR);
525 self::$default_calendar[$a_usr_id][$a_type_id]->setTitle($a_title);
526 self::$default_calendar[$a_usr_id][$a_type_id]->setObjId($a_usr_id);
527 self::$default_calendar[$a_usr_id][$a_type_id]->add();
528
529 return self::$default_calendar[$a_usr_id][$a_type_id];
530 }
531
532
533 //
534 // BOOTSTRAP DATEPICKER
535 //
536
544 public static function getUserDateFormat($a_add_time = false, $a_for_parsing = false)
545 {
546 global $DIC;
547
548 $ilUser = $DIC['ilUser'];
549
550 // getDateFormat() should return calendar defaults for ANONYMOUS user
551 switch ($ilUser->getDateFormat()) {
553 $format = "DD.MM.YYYY";
554 break;
555
557 $format = "YYYY-MM-DD";
558 break;
559
561 $format = "MM/DD/YYYY";
562 break;
563 }
564 if ($a_add_time) {
565 $format .= " " . (($ilUser->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_24)
566 ? "HH:mm"
567 : "hh:mma");
568 if ($a_add_time == 2) {
569 $format .= ":ss";
570 }
571 }
572
573 // translate datepicker format to PHP format
574 if ((bool) $a_for_parsing) {
575 $format = str_replace("DD", "d", $format);
576 $format = str_replace("MM", "m", $format);
577 $format = str_replace("mm", "i", $format);
578 $format = str_replace("YYYY", "Y", $format);
579 $format = str_replace("HH", "H", $format);
580 $format = str_replace("hh", "h", $format);
581 }
582
583 return $format;
584 }
585
586 public static function initDateTimePicker()
587 {
588 global $DIC;
589
590 $tpl = $DIC['tpl'];
591
592 if (!self::$init_datetimepicker) {
593 $tpl->addJavaScript("./libs/bower/bower_components/moment/min/moment-with-locales.min.js");
594
595 // unminified version does not work with jQuery 3.0
596 // https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1684
597 $tpl->addJavaScript("./libs/bower/bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js");
598
599 $tpl->addJavaScript("Services/Form/js/Form.js"); // see ilPropertyFormGUI
600
601 self::$init_datetimepicker = true;
602 }
603 }
604
617 public static function addDateTimePicker($a_id, $a_add_time = null, array $a_custom_config = null, $a_id2 = null, $a_custom_config2 = null, $a_toggle_id = null, $a_subform_id = null)
618 {
619 global $DIC;
620
621 $tpl = $DIC['tpl'];
622 $ilUser = $DIC['ilUser'];
623
625
626 // weekStart is currently governed by locale and cannot be changed
627
628 // fix for mantis 22994 => default to english language
629 $language = 'en';
630 if ($ilUser->getLanguage() != 'ar') {
631 $language = $ilUser->getLanguage();
632 }
633 $default = array(
634 'locale' => $language
635 ,'stepping' => 5
636 ,'useCurrent' => false
637 ,'calendarWeeks' => true
638 ,'toolbarPlacement' => 'top'
639 // ,'showTodayButton' => true
640 ,'showClear' => true
641 // ,'showClose' => true
642 ,'keepInvalid' => true
643 ,'sideBySide' => true
644 // ,'collapse' => false
645 ,'format' => self::getUserDateFormat($a_add_time)
646 );
647
648 $config = (!$a_custom_config)
649 ? $default
650 : array_merge($default, $a_custom_config);
651
652 $tpl->addOnLoadCode('$("#' . $a_id . '").datetimepicker(' . json_encode($config) . ')');
653
654
655 // optional 2nd picker aka duration
656 if ($a_id2) {
657 $config2 = (!$a_custom_config2)
658 ? $default
659 : array_merge($default, $a_custom_config2);
660
661 $config2["useCurrent"] = false; //Important! See issue #1075
662
663 $tpl->addOnLoadCode('$("#' . $a_id2 . '").datetimepicker(' . json_encode($config2) . ')');
664
665 // duration limits, diff and subform handling
666 $tpl->addOnLoadCode('il.Form.initDateDurationPicker("' . $a_id . '","' . $a_id2 . '","' . $a_toggle_id . '","' . $a_subform_id . '");');
667 } elseif ($a_subform_id) {
668 // subform handling
669 $tpl->addOnLoadCode('il.Form.initDatePicker("' . $a_id . '","' . $a_subform_id . '");');
670 }
671 }
672
679 public static function parseDateString($a_date, $a_add_time = null, $a_use_generic_format = false)
680 {
681 global $DIC;
682
683 $ilUser = $DIC['ilUser'];
684
685 if (!$a_use_generic_format) {
686 $out_format = self::getUserDateFormat($a_add_time, true);
687 } else {
688 $out_format = $a_add_time
689 ? "Y-m-d H:i:s"
690 : "Y-m-d";
691 }
692 $tmp = date_parse_from_format($out_format, $a_date);
693
694 $date = null;
695
696 if (!$tmp["error_count"] &&
697 !$tmp["warning_count"]) {
698 $format = $tmp["year"] . "-" .
699 str_pad($tmp["month"], 2, "0", STR_PAD_LEFT) . "-" .
700 str_pad($tmp["day"], 2, "0", STR_PAD_LEFT);
701
702 if ($a_add_time) {
703 $format .= " " .
704 str_pad($tmp["hour"], 2, "0", STR_PAD_LEFT) . ":" .
705 str_pad($tmp["minute"], 2, "0", STR_PAD_LEFT) . ":" .
706 str_pad($tmp["second"], 2, "0", STR_PAD_LEFT);
707
708 $date = new ilDateTime($format, IL_CAL_DATETIME, $ilUser->getTimeZone());
709 } else {
710 $date = new ilDate($format, IL_CAL_DATE);
711 }
712 }
713
714 return array(
715 "date" => $date
716 , "warnings" => sizeof($tmp["warnings"])
717 ? $tmp["warnings"]
718 : null
719 , "errors" => sizeof($tmp["errors"])
720 ? $tmp["errors"]
721 : null
722 );
723 }
724
732 public static function parseIncomingDate($a_value, $a_add_time = null)
733 {
734 // already datetime object?
735 if (is_object($a_value) &&
736 $a_value instanceof ilDateTime) {
737 return $a_value;
738 } elseif (trim($a_value)) {
739 // try user-specific format
740 $parsed = self::parseDateString($a_value, $a_add_time);
741 if (is_object($parsed["date"])) {
742 return $parsed["date"];
743 } else {
744 // try generic format
745 $parsed = self::parseDateString($a_value, $a_add_time, true);
746 if (is_object($parsed["date"])) {
747 return $parsed["date"];
748 }
749 }
750 }
751 }
752}
$tpl
Definition: ilias.php:10
$default
Definition: build.php:20
An exception for terminatinating execution or to throw for unit testing.
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.
Class ilCalendarUtil.
static _getShortTimeZoneList()
get short timezone list
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
static _isToday($date)
check if a date is today
static initJSCalendar()
Init Javascript Calendar.
static _getMaxDayOfMonth($a_year, $a_month)
get max day of month 2008,2 => 29
static getHourSelection($a_format)
Get hour selectio depending on user specific hour format.
static parseDateString($a_date, $a_add_time=null, $a_use_generic_format=false)
Parse (incoming) string to date/time object.
static _numericDayToString($a_day, $a_long=true)
get
static _buildWeekDayList($a_day, $a_weekstart)
build week day list
static _buildMonthDayList($a_month, $a_year, $weekstart)
Build a month day list.
static calculateFontColor($a_html_color_code)
Calculate best font color from html hex color code.
static addDateTimePicker($a_id, $a_add_time=null, array $a_custom_config=null, $a_id2=null, $a_custom_config2=null, $a_toggle_id=null, $a_subform_id=null)
Add date time picker to element.
static _isLeapYear($a_year)
check if a given year is a leap year
static _numericMonthToString($a_month, $a_long=true)
numeric month to string
static getZoneInfoFile($a_tz)
static initDefaultCalendarByType($a_type_id, $a_usr_id, $a_title, $a_create=false)
Init the default calendar for given type and user.
static getUserDateFormat($a_add_time=false, $a_for_parsing=false)
Parse current user setting into date/time format.
List of dates.
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
Class for single dates.
$i
Definition: disco.tpl.php:19
$config
Definition: bootstrap.php:15
$format
Definition: metadata.php:141
$row
$query
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$start
Definition: bench.php:8