returns an ICSExport calendar object by supplying a Silverstripe calendar
@param type $cal
977794
public static function ics_from_sscal($cal)
        {
            $events = $cal->Events();
            $eventsArr = $events->toNestedArray();

            //Debug::dump($eventsArr);
            //return false;
            $ics = new ICSExport($eventsArr);
            return $ics;
        }
1170819
private static String yearAndQuarter(Calendar cal) {
		return new StringBuilder().append(cal.get(Calendar.YEAR)).append(cal.get(Calendar.MONTH) / 3 + 1).toString();
	}
1318218
private function createCalendar(string $locale = null) : \IntlCalendar
    {
        $timezone = \IntlTimeZone::createTimeZone($this->date()->getTimezone()->getName());
        $calendar = \IntlCalendar::createInstance($timezone, $locale);
        
        $calendar->setTime($this->timestampWithMillisecond());
        
        return $calendar;
    }
1189941
public function getExtraFormTypesAction(
        $_format,
        ExtraFormTypeRegistryInterface $extraFormTypeRegistry
    ) {
        $view = View::create()->setFormat($_format);

        if ('html' === $_format) {
            $form = $this->createForm('extra_form_type_choice');

            $view
                ->setData($form->createView())
                ->setTemplate('IDCIExtraFormBundle:Api:form.html.twig')
                ->setTemplateVar('form')
            ;
        } else {
            $types = $extraFormTypeRegistry->getTypes();
            ksort($types);
            $view->setData(array_values($types));
        }

        return $this->handleView($view);
    }
887893
public function serializeDateInterval(SerializationVisitorInterface $visitor, \DateInterval $date, array $type, SerializationContext $context)
    {
        $iso8601DateIntervalString = $this->format($date);

        if ($visitor instanceof XmlSerializationVisitor && false === $this->xmlCData) {
            return $visitor->visitSimpleString($iso8601DateIntervalString, $type);
        }

        return $visitor->visitString($iso8601DateIntervalString, $type);
    }
987174
public function translateFromRequest($namespace, Calendar $calendar, $request)
    {
        $sets = $request->request->get($namespace . '_repetitionSetID');
        $r = $request->request;

        $repetitions = array();

        foreach($sets as $repetitionSetID) {

            $dateStart = $r->get($namespace . '_pdStartDate_' . $repetitionSetID);
            $dateEnd = $r->get($namespace . '_pdEndDate_' . $repetitionSetID);
            if ($dateStart || $dateEnd) {

                // create a Repetition object

                $pd = new EventRepetition();

                $timezone = $calendar->getSite()->getConfigRepository()->get('timezone');
                if (!$timezone) {
                    $timezone = date_default_timezone_get();
                }

                $timezone = new \DateTimeZone($timezone);
                $pd->setTimezone($timezone);

                if ($r->get($namespace . '_pdStartDateAllDayActivate_' . $repetitionSetID)) {
                    $pd->setStartDateAllDay(true);
                    $pd->setEndDateAllDay(true);
                    $dateStart = date('Y-m-d 00:00:00', strtotime($dateStart));
                    $dateEnd = date('Y-m-d 23:59:59', strtotime($dateEnd));
                } else {
                    $pd->setStartDateAllDay(0);
                    // Grab the times.
                    $dateStart = date('Y-m-d H:i:s', strtotime($dateStart . ' ' . $r->get($namespace . '_pdStartDateSelectTime_' . $repetitionSetID)));
                    $dateEnd = date('Y-m-d H:i:s', strtotime($dateEnd . ' ' . $r->get($namespace . '_pdEndDateSelectTime_' . $repetitionSetID)));
                }

                $pd->setStartDate($dateStart);
                $pd->setEndDate($dateEnd);

                if ($r->get($namespace . '_pdRepeatPeriod_' . $repetitionSetID) && $r->get($namespace . '_pdRepeat_' . $repetitionSetID)) {
                    if ($r->get($namespace . '_pdRepeatPeriod_' . $repetitionSetID) == 'daily') {
                        $pd->setRepeatPeriod($pd::REPEAT_DAILY);
                        $pd->setRepeatEveryNum($r->get($namespace . '_pdRepeatPeriodDaysEvery_' . $repetitionSetID));
                    } elseif ($r->get($namespace . '_pdRepeatPeriod_' . $repetitionSetID) == 'weekly') {
                        $pd->setRepeatPeriod($pd::REPEAT_WEEKLY);
                        $pd->setRepeatEveryNum($r->get($namespace . '_pdRepeatPeriodWeeksEvery_' . $repetitionSetID));
                        $pd->setRepeatPeriodWeekDays($r->get($namespace . '_pdRepeatPeriodWeeksDays_' . $repetitionSetID));
                    } elseif ($r->get($namespace . '_pdRepeatPeriod_' . $repetitionSetID) == 'monthly') {
                        $pd->setRepeatPeriod($pd::REPEAT_MONTHLY);
                        $repeat_by = $r->get($namespace . '_pdRepeatPeriodMonthsRepeatBy_' . $repetitionSetID);
                        $repeat = $pd::MONTHLY_REPEAT_WEEKLY;
                        switch ($repeat_by) {
                            case 'week':
                                $repeat = $pd::MONTHLY_REPEAT_WEEKLY;
                                break;
                            case 'month':
                                $repeat = $pd::MONTHLY_REPEAT_MONTHLY;
                                break;
                            case 'lastweekday':
                                $repeat = $pd::MONTHLY_REPEAT_LAST_WEEKDAY;
                                $dotw = $r->get($namespace . '_pdRepeatPeriodMonthsRepeatLastDay_' . $repetitionSetID);
                                if (!$dotw) {
                                    $dotw = 0;
                                }
                                $pd->setRepeatMonthLastWeekday($dotw);
                                break;
                        }

                        $pd->setRepeatMonthBy($repeat);
                        $pd->setRepeatEveryNum($r->get($namespace . '_pdRepeatPeriodMonthsEvery_' . $repetitionSetID));
                    }

                    $pdEndRepeatDate = $r->get($namespace . '_pdEndRepeatDate_' . $repetitionSetID);
                    if ($pdEndRepeatDate == 'date') {
                        $pd->setRepeatPeriodEnd($this->formDateTime->translate($namespace . '_pdEndRepeatDateSpecific_' . $repetitionSetID));
                    } else {
                        $pd->setRepeatPeriodEnd(null);
                    }
                } else {
                    $pd->setRepeatPeriod($pd::REPEAT_NONE);
                }

                $reuseExisting = false;
                $comparator = new Comparator();
                if ($r->get($namespace . '_repetitionID_' . $repetitionSetID)) {
                    $pdEntity = $this->getByID($r->get($namespace . '_repetitionID_' . $repetitionSetID));
                    if ($pdEntity) {
                        $repetitionObject = $pdEntity->getRepetitionObject();
                        // If the object is the same as the one we have stored in the db, reuse the same object.
                        if ($comparator->areEqual($repetitionObject, $pd)) {
                            $repetitions[] = $pdEntity;
                            $reuseExisting = true;
                        }
                    }
                }

                if (!$reuseExisting) {
                    $pdEntity = new CalendarEventRepetition($pd);
                    $repetitions[] = $pdEntity;
                }
            }
        }

        return $repetitions;
    }
754730
public function getHolidayListInICalendarFormat(HolidayList $holidayList, TranslatorInterface $translator = null, DateHelper $dateHelper = null)
    {
        $calendarFormatter = new ICalendarFormatter($translator, $dateHelper);
        $content = [];
        $content[] = $calendarFormatter->getHeader();
        $content = array_merge($content, $calendarFormatter->formatList($holidayList));
        $content[] = $calendarFormatter->getFooter();

        return implode(ICalendarFormatter::LINE_ENDING, $content).ICalendarFormatter::LINE_ENDING;
    }
1218314
public static function getExporter($type) {
        // normalize type
        $className = 'Garp_Content_Export_' . ucfirst($type);
        $obj = new $className();
        if (!$obj instanceof Garp_Content_Export_Abstract) {
            throw new Garp_Content_Export_Exception(
                "Class $className does not implement Garp_Content_Export_Abstract."
            );
        }
        return $obj;
    }
183390
protected function getDatePattern($datetype, $timetype, $calendar = \IntlDateFormatter::GREGORIAN)
    {
        $createPattern =
            (is_int($datetype) && $datetype !== \IntlDateFormatter::NONE) ||
            (is_int($timetype) && $timetype !== \IntlDateFormatter::NONE);
        
        $pattern = $createPattern ? $this->getDatePatternFormatter($datetype, $timetype, $calendar)->getPattern() : '';
        
        return trim(
            (is_string($datetype) ? $datetype . ' ' : '') .
            preg_replace('/\byy?\b/', 'yyyy', $pattern) .
            (is_string($timetype) ? ' ' . $timetype : '')
        );
    }
987560
public function addCalendarType($type, $calendarType)
	{
		if (is_string($calendarType) and !class_exists($calendarType)) {
			throw new \InvalidArgumentException("Class {$calendarType} does not exist.");
		} elseif (!in_array('Plummer\Calendarful\Calendar\CalendarInterface', class_implements($calendarType, false))) {
			throw new \InvalidArgumentException('File or File path required.');
		}

		$this->calendarTypes[$type] = is_string($calendarType) ?
			$calendarType :
			get_class($calendarType);
	}
571559
private Calendar cleanHistCalendar(Calendar cal) {
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.HOUR, 0);
        return cal;
    }
369669
private function parseDate($date): AbstractCalendarDate
    {
        // Valid calendar escape specified? - use it
        if (preg_match('/^(@#D(?:GREGORIAN|JULIAN|HEBREW|HIJRI|JALALI|FRENCH R|ROMAN)+@) ?(.*)/', $date, $match)) {
            $cal  = $match[1];
            $date = $match[2];
        } else {
            $cal = '';
        }
        // A date with a month: DM, M, MY or DMY
        if (preg_match('/^(\d?\d?) ?(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|TSH|CSH|KSL|TVT|SHV|ADR|ADS|NSN|IYR|SVN|TMZ|AAV|ELL|VEND|BRUM|FRIM|NIVO|PLUV|VENT|GERM|FLOR|PRAI|MESS|THER|FRUC|COMP|MUHAR|SAFAR|RABI[AT]|JUMA[AT]|RAJAB|SHAAB|RAMAD|SHAWW|DHUAQ|DHUAH|FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN) ?((?:\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d)?)$/', $date, $match)) {
            $d = $match[1];
            $m = $match[2];
            $y = $match[3];
        } elseif (preg_match('/^(\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d)$/', $date, $match)) {
            // A date with just a year
            $d = '';
            $m = '';
            $y = $match[1];
        } else {
            // An invalid date - do the best we can.
            $d = '';
            $m = '';
            $y = '';
            // Look for a 3/4 digit year anywhere in the date
            if (preg_match('/\b(\d{3,4})\b/', $date, $match)) {
                $y = $match[1];
            }
            // Look for a month anywhere in the date
            if (preg_match('/(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|TSH|CSH|KSL|TVT|SHV|ADR|ADS|NSN|IYR|SVN|TMZ|AAV|ELL|VEND|BRUM|FRIM|NIVO|PLUV|VENT|GERM|FLOR|PRAI|MESS|THER|FRUC|COMP|MUHAR|SAFAR|RABI[AT]|JUMA[AT]|RAJAB|SHAAB|RAMAD|SHAWW|DHUAQ|DHUAH|FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN)/', $date, $match)) {
                $m = $match[1];
                // Look for a day number anywhere in the date
                if (preg_match('/\b(\d\d?)\b/', $date, $match)) {
                    $d = $match[1];
                }
            }
        }

        // Unambiguous dates - override calendar escape
        if (preg_match('/^(TSH|CSH|KSL|TVT|SHV|ADR|ADS|NSN|IYR|SVN|TMZ|AAV|ELL)$/', $m)) {
            $cal = JewishDate::ESCAPE;
        } elseif (preg_match('/^(VEND|BRUM|FRIM|NIVO|PLUV|VENT|GERM|FLOR|PRAI|MESS|THER|FRUC|COMP)$/', $m)) {
            $cal = FrenchDate::ESCAPE;
        } elseif (preg_match('/^(MUHAR|SAFAR|RABI[AT]|JUMA[AT]|RAJAB|SHAAB|RAMAD|SHAWW|DHUAQ|DHUAH)$/', $m)) {
            $cal = HijriDate::ESCAPE; // This is a WT extension
        } elseif (preg_match('/^(FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN)$/', $m)) {
            $cal = JalaliDate::ESCAPE; // This is a WT extension
        } elseif (preg_match('/^\d{1,4}( B\.C\.)|\d\d\d\d\/\d\d$/', $y)) {
            $cal = JulianDate::ESCAPE;
        }

        // Ambiguous dates - don't override calendar escape
        if ($cal === '') {
            if (preg_match('/^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)$/', $m)) {
                $cal =  GregorianDate::ESCAPE;
            } elseif (preg_match('/^[345]\d\d\d$/', $y)) {
                // Year 3000-5999
                $cal = JewishDate::ESCAPE;
            } else {
                $cal = GregorianDate::ESCAPE;
            }
        }
        // Now construct an object of the correct type
        switch ($cal) {
            case GregorianDate::ESCAPE:
                return new GregorianDate([
                    $y,
                    $m,
                    $d,
                ]);
            case JulianDate::ESCAPE:
                return new JulianDate([
                    $y,
                    $m,
                    $d,
                ]);
            case JewishDate::ESCAPE:
                return new JewishDate([
                    $y,
                    $m,
                    $d,
                ]);
            case HijriDate::ESCAPE:
                return new HijriDate([
                    $y,
                    $m,
                    $d,
                ]);
            case FrenchDate::ESCAPE:
                return new FrenchDate([
                    $y,
                    $m,
                    $d,
                ]);
            case JalaliDate::ESCAPE:
                return new JalaliDate([
                    $y,
                    $m,
                    $d,
                ]);
            case RomanDate::ESCAPE:
                return new RomanDate([
                    $y,
                    $m,
                    $d,
                ]);
            default:
                throw new DomainException('Invalid calendar');
        }
    }
91714
public function calendarQueryReport($report)
    {
        $path = $this->server->getRequestUri();

        $needsJson = 'application/calendar+json' === $report->contentType;

        $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
        $depth = $this->server->getHTTPDepth(0);

        // The default result is an empty array
        $result = [];

        $calendarTimeZone = null;
        if ($report->expand) {
            // We're expanding, and for that we need to figure out the
            // calendar's timezone.
            $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone';
            $tzResult = $this->server->getProperties($path, [$tzProp]);
            if (isset($tzResult[$tzProp])) {
                // This property contains a VCALENDAR with a single
                // VTIMEZONE.
                $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]);
                $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();

                // Destroy circular references so PHP will garbage collect the
                // object.
                $vtimezoneObj->destroy();
            } else {
                // Defaulting to UTC.
                $calendarTimeZone = new DateTimeZone('UTC');
            }
        }

        // The calendarobject was requested directly. In this case we handle
        // this locally.
        if (0 == $depth && $node instanceof ICalendarObject) {
            $requestedCalendarData = true;
            $requestedProperties = $report->properties;

            if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) {
                // We always retrieve calendar-data, as we need it for filtering.
                $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data';

                // If calendar-data wasn't explicitly requested, we need to remove
                // it after processing.
                $requestedCalendarData = false;
            }

            $properties = $this->server->getPropertiesForPath(
                $path,
                $requestedProperties,
                0
            );

            // This array should have only 1 element, the first calendar
            // object.
            $properties = current($properties);

            // If there wasn't any calendar-data returned somehow, we ignore
            // this.
            if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) {
                $validator = new CalendarQueryValidator();

                $vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
                if ($validator->validate($vObject, $report->filters)) {
                    // If the client didn't require the calendar-data property,
                    // we won't give it back.
                    if (!$requestedCalendarData) {
                        unset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
                    } else {
                        if ($report->expand) {
                            $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone);
                        }
                        if ($needsJson) {
                            $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize());
                        } elseif ($report->expand) {
                            $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize();
                        }
                    }

                    $result = [$properties];
                }
                // Destroy circular references so PHP will garbage collect the
                // object.
                $vObject->destroy();
            }
        }

        if ($node instanceof ICalendarObjectContainer && 0 === $depth) {
            if (0 === strpos((string) $this->server->httpRequest->getHeader('User-Agent'), 'MSFT-')) {
                // Microsoft clients incorrectly supplied depth as 0, when it actually
                // should have set depth to 1. We're implementing a workaround here
                // to deal with this.
                //
                // This targets at least the following clients:
                //   Windows 10
                //   Windows Phone 8, 10
                $depth = 1;
            } else {
                throw new BadRequest('A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1');
            }
        }

        // If we're dealing with a calendar, the calendar itself is responsible
        // for the calendar-query.
        if ($node instanceof ICalendarObjectContainer && 1 == $depth) {
            $nodePaths = $node->calendarQuery($report->filters);

            foreach ($nodePaths as $path) {
                list($properties) =
                    $this->server->getPropertiesForPath($this->server->getRequestUri().'/'.$path, $report->properties);

                if (($needsJson || $report->expand)) {
                    $vObject = VObject\Reader::read($properties[200]['{'.self::NS_CALDAV.'}calendar-data']);

                    if ($report->expand) {
                        $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone);
                    }

                    if ($needsJson) {
                        $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize());
                    } else {
                        $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize();
                    }

                    // Destroy circular references so PHP will garbage collect the
                    // object.
                    $vObject->destroy();
                }
                $result[] = $properties;
            }
        }

        $prefer = $this->server->getHTTPPrefer();

        $this->server->httpResponse->setStatus(207);
        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
        $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
        $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, 'minimal' === $prefer['return']));
    }
942615
public function getCalendar() : ?string 
    {
        if ( ! $this->hasCalendar()) {
            $this->setCalendar($this->getDefaultCalendar());
        }
        return $this->calendar;
    }
153100
private function sendGetExportDocRequest($data) {
		switch($this->getMayor()) {
			case 1:
				return $this->getSoapClient()->getExportDocDD($data);
			case 2:
			default:
				return $this->getSoapClient()->getExportDoc($data);
		}
	}
628067
public function httpMkCalendar(RequestInterface $request, ResponseInterface $response)
    {
        $body = $request->getBodyAsString();
        $path = $request->getPath();

        $properties = [];

        if ($body) {
            try {
                $mkcalendar = $this->server->xml->expect(
                    '{urn:ietf:params:xml:ns:caldav}mkcalendar',
                    $body
                );
            } catch (\Sabre\Xml\ParseException $e) {
                throw new BadRequest($e->getMessage(), 0, $e);
            }
            $properties = $mkcalendar->getProperties();
        }

        // iCal abuses MKCALENDAR since iCal 10.9.2 to create server-stored
        // subscriptions. Before that it used MKCOL which was the correct way
        // to do this.
        //
        // If the body had a {DAV:}resourcetype, it means we stumbled upon this
        // request, and we simply use it instead of the pre-defined list.
        if (isset($properties['{DAV:}resourcetype'])) {
            $resourceType = $properties['{DAV:}resourcetype']->getValue();
        } else {
            $resourceType = ['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar'];
        }

        $this->server->createCollection($path, new MkCol($resourceType, $properties));

        $response->setStatus(201);
        $response->setHeader('Content-Length', 0);

        // This breaks the method chain.
        return false;
    }
665930
public static Calendar getCal(final Date date) {
        if (date == null) {
            return null;
        }
        final Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return blastTime(cal);
    }