35 if ($date instanceof \
ilDate) {
45 $ilUser = $DIC[
'ilUser'];
46 if (!is_object(self::$today)) {
64 $month = $a_month < 10 ?
'0' . $a_month : $a_month;
65 return $a_long ?
$lng->txt(
'month_' . $month .
'_long') :
$lng->txt(
'month_' . $month .
'_short');
79 $lng->loadLanguageModule(
'dateplaner');
80 static $days = array(
'Su',
'Mo',
'Tu',
'We',
'Th',
'Fr',
'Sa',
'Su');
82 return $a_long ?
$lng->txt($days[$a_day] .
'_long') :
$lng->txt($days[$a_day] .
'_short');
96 $start = clone $a_day;
98 $day_diff = $a_weekstart - $start_info[
'isoday'];
99 if (abs($day_diff) === 7) {
103 $day_list->add($start);
104 for ($i = 1; $i < 7; $i++) {
106 $day_list->add($start);
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;
127 $days_in_month = self::_getMaxDayOfMonth($a_year, $a_month);
128 $days_in_prev_month = self::_getMaxDayOfMonth($a_year, $prev_month);
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;
138 $first_day_offset = (($weekday - $weekstart) < 0) ? 6 : $weekday - $weekstart;
140 for ($i = 0; $i < 42; $i++) {
141 if ($i < $first_day_offset) {
142 $day = $days_in_prev_month - $first_day_offset + $i + 1;
144 $day_list->add(
new ilDate(
150 $days_in_prev_month - $first_day_offset + $i + 1,
155 } elseif ($i < $days_in_month + $first_day_offset) {
156 $day = $i - $first_day_offset + 1;
158 $day_list->add(
new ilDate(
164 $i - $first_day_offset + 1,
170 $day = $i - $days_in_month - $first_day_offset + 1;
171 $day_list->add(
new ilDate(
177 $i - $days_in_month - $first_day_offset + 1,
183 if ($i == 34 and ($day < 15 or $day == $days_in_month)) {
197 if (self::$init_done ==
"done") {
201 $lng->loadLanguageModule(
"jscalendar");
203 "CALENDAR_LANG_JAVASCRIPT",
204 "calendar_javascript",
206 "components/ILIAS/Calendar" 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();
272 self::$init_done =
"done";
277 if (!array_key_exists($a_tz, self::_getShortTimeZoneList())) {
280 $timezone_filename = str_replace(
'/',
'_', $a_tz);
281 $timezone_filename .=
'.ics';
282 return '../components/ILIAS/Calendar/zoneinfo/' . $timezone_filename;
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' 369 if ($a_year % 4 == 0) {
371 if ($a_year % 100 == 0) {
387 if (function_exists(
'cal_days_in_month')) {
388 return cal_days_in_month(CAL_GREGORIAN, $a_month, $a_year);
390 return (
int) date(
't', mktime(0, 0, 0, $a_month, 1, $a_year));
400 if (strpos($a_html_color_code,
'#') !== 0 or strlen($a_html_color_code) != 7) {
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";
419 for ($i = 0; $i < 24; $i++) {
420 $options[$i] = sprintf(
'%02d:00', $i);
425 for ($i = 0; $i < 24; $i++) {
426 $options[$i] = date(
'h a', mktime($i, 0, 0, 1, 1, 2000));
440 bool $a_create =
false 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];
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');
454 return self::$default_calendar[$a_usr_id][$a_type_id] =
new ilCalendarCategory($row->cat_id);
463 self::$default_calendar[$a_usr_id][$a_type_id]->setType($a_type_id);
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();
469 return self::$default_calendar[$a_usr_id][$a_type_id];
478 public static function getUserDateFormat(
int $a_add_time = 0,
bool $a_for_parsing =
false): string
482 $ilUser = $DIC[
'ilUser'];
484 $format = (string) $ilUser->getDateFormat();
490 if ($a_add_time == 2) {
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);
512 $tpl = $DIC->ui()->mainTemplate();
514 if (!self::$init_datetimepicker) {
519 $tpl->addJavaScript(
"assets/js/Form.js");
520 self::$init_datetimepicker =
true;
532 public static function parseDateString(
string $date,
bool $add_time =
false, ?
string $force_format =
null): array
536 $ilUser = $DIC[
'ilUser'];
537 if (!$force_format) {
538 $out_format = self::getUserDateFormat($add_time,
true);
540 $out_format = $force_format;
543 $tmp = date_parse_from_format($out_format, $date);
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);
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);
565 "date" => $return_date
567 "warnings" =>
sizeof($tmp[
"warnings"])
571 "errors" =>
sizeof($tmp[
"errors"])
588 } elseif (!trim($value)) {
593 $parsed = self::parseDateString($value, $add_time);
594 if (is_object($parsed[
'date'])) {
595 return $parsed[
'date'];
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'];
611 $parsed = self::parseDateString($value, $add_time, $format);
612 if (is_object($parsed[
'date'])) {
613 return $parsed[
'date'];
static _getMaxDayOfMonth(int $a_year, int $a_month)
get max day of month 2008,2 => 29
static parseIncomingDate($value, bool $add_time=false)
Try to parse incoming value to date object.
static _buildMonthDayList(int $a_month, int $a_year, int $weekstart)
Build a month day list.
static initDateTimePicker()
static _numericMonthToString(int $a_month, bool $a_long=true, ?ilLanguage $lng=null)
numeric month to string
get(int $a_format, string $a_format_str='', string $a_tz='')
static _buildWeekDayList(ilDate $a_day, int $a_weekstart)
build week day list public
static getZoneInfoFile($a_tz)
static bool $init_datetimepicker
Stores calendar categories.
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 getHourSelection(int $a_format)
Get hour selection depending on user specific hour format.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _numericDayToString(int $a_day, bool $a_long=true, ?ilLanguage $lng=null)
static convertDateToUtcDBTimestamp(?\ilDateTime $date=null)
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 _isLeapYear(int $a_year)
check if a given year is a leap year
static array $default_calendar
static calculateFontColor(string $a_html_color_code)
Calculate best font color from html hex color code.
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static parseDateString(string $date, bool $add_time=false, ?string $force_format=null)
Parse (incoming) string to date/time object.
static _isToday(ilDateTime $date)