public static function create($time, int $courseid, int $categoryid = null) : calendar_information {
        $calendar = new static(0, 0, 0, $time);
        if ($courseid != SITEID && !empty($courseid)) {
            // Course ID must be valid and existing.
            $course = get_course($courseid);
            $calendar->context = context_course::instance($course->id);

            if (!$course->visible && !is_role_switched($course->id)) {
                require_capability('moodle/course:viewhiddencourses', $calendar->context);
            }

            $courses = [$course->id => $course];
            $category = (\core_course_category::get($course->category, MUST_EXIST, true))->get_db_record();
        } else if (!empty($categoryid)) {
            $course = get_site();
            $courses = calendar_get_default_courses(null, 'id, category, groupmode, groupmodeforce');

            // Filter available courses to those within this category or it's children.
            $ids = [$categoryid];
            $category = \core_course_category::get($categoryid);
            $ids = array_merge($ids, array_keys($category->get_children()));
            $courses = array_filter($courses, function($course) use ($ids) {
                return array_search($course->category, $ids) !== false;
            });
            $category = $category->get_db_record();

            $calendar->context = context_coursecat::instance($categoryid);
        } else {
            $course = get_site();
            $courses = calendar_get_default_courses(null, 'id, category, groupmode, groupmodeforce');
            $category = null;

            $calendar->context = context_system::instance();
        }

        $calendar->set_sources($course, $courses, $category);

        return $calendar;
    }