Recurr\Rule::getString PHP Метод

getString() публичный Метод

Get the RRULE as a string
public getString ( $timezoneType = self::TZ_FLOAT ) : string
Результат string
    public function getString($timezoneType = self::TZ_FLOAT)
    {
        $format = 'Ymd\\THis';
        $parts = array();
        // FREQ
        $parts[] = 'FREQ=' . $this->getFreqAsText();
        // UNTIL or COUNT
        $until = $this->getUntil();
        $count = $this->getCount();
        if (!empty($until)) {
            if ($timezoneType === self::TZ_FIXED) {
                $u = clone $until;
                $u->setTimezone(new \DateTimeZone('UTC'));
                $parts[] = 'UNTIL=' . $u->format($format . '\\Z');
            } else {
                $parts[] = 'UNTIL=' . $until->format($format);
            }
        } elseif (!empty($count)) {
            $parts[] = 'COUNT=' . $count;
        }
        // DTSTART
        if ($this->isStartDateFromDtstart) {
            if ($timezoneType === self::TZ_FIXED) {
                $d = $this->getStartDate();
                $tzid = $d->getTimezone()->getName();
                $date = $d->format($format);
                $parts[] = "DTSTART;TZID={$tzid}:{$date}";
            } else {
                $parts[] = 'DTSTART=' . $this->getStartDate()->format($format);
            }
        }
        // DTEND
        if ($this->endDate instanceof \DateTime) {
            if ($timezoneType === self::TZ_FIXED) {
                $d = $this->getEndDate();
                $tzid = $d->getTimezone()->getName();
                $date = $d->format($format);
                $parts[] = "DTEND;TZID={$tzid}:{$date}";
            } else {
                $parts[] = 'DTEND=' . $this->getEndDate()->format($format);
            }
        }
        // INTERVAL
        $interval = $this->getInterval();
        if ($this->isExplicitInterval && !empty($interval)) {
            $parts[] = 'INTERVAL=' . $interval;
        }
        // BYSECOND
        $bySecond = $this->getBySecond();
        if (!empty($bySecond)) {
            $parts[] = 'BYSECOND=' . implode(',', $bySecond);
        }
        // BYMINUTE
        $byMinute = $this->getByMinute();
        if (!empty($byMinute)) {
            $parts[] = 'BYMINUTE=' . implode(',', $byMinute);
        }
        // BYHOUR
        $byHour = $this->getByHour();
        if (!empty($byHour)) {
            $parts[] = 'BYHOUR=' . implode(',', $byHour);
        }
        // BYDAY
        $byDay = $this->getByDay();
        if (!empty($byDay)) {
            $parts[] = 'BYDAY=' . implode(',', $byDay);
        }
        // BYMONTHDAY
        $byMonthDay = $this->getByMonthDay();
        if (!empty($byMonthDay)) {
            $parts[] = 'BYMONTHDAY=' . implode(',', $byMonthDay);
        }
        // BYYEARDAY
        $byYearDay = $this->getByYearDay();
        if (!empty($byYearDay)) {
            $parts[] = 'BYYEARDAY=' . implode(',', $byYearDay);
        }
        // BYWEEKNO
        $byWeekNumber = $this->getByWeekNumber();
        if (!empty($byWeekNumber)) {
            $parts[] = 'BYWEEKNO=' . implode(',', $byWeekNumber);
        }
        // BYMONTH
        $byMonth = $this->getByMonth();
        if (!empty($byMonth)) {
            $parts[] = 'BYMONTH=' . implode(',', $byMonth);
        }
        // BYSETPOS
        $bySetPosition = $this->getBySetPosition();
        if (!empty($bySetPosition)) {
            $parts[] = 'BYSETPOS=' . implode(',', $bySetPosition);
        }
        // WKST
        $weekStart = $this->getWeekStart();
        if ($this->weekStartDefined && !empty($weekStart)) {
            $parts[] = 'WKST=' . $weekStart;
        }
        // RDATE
        $rDates = $this->getRDates();
        if (!empty($rDates)) {
            foreach ($rDates as $key => $inclusion) {
                $format = 'Ymd';
                if ($inclusion->hasTime) {
                    $format .= '\\THis';
                    if ($inclusion->isUtcExplicit) {
                        $format .= '\\Z';
                    }
                }
                $rDates[$key] = $inclusion->date->format($format);
            }
            $parts[] = 'RDATE=' . implode(',', $rDates);
        }
        // EXDATE
        $exDates = $this->getExDates();
        if (!empty($exDates)) {
            foreach ($exDates as $key => $exclusion) {
                $format = 'Ymd';
                if ($exclusion->hasTime) {
                    $format .= '\\THis';
                    if ($exclusion->isUtcExplicit) {
                        $format .= '\\Z';
                    }
                }
                $exDates[$key] = $exclusion->date->format($format);
            }
            $parts[] = 'EXDATE=' . implode(',', $exDates);
        }
        return implode(';', $parts);
    }

Usage Example

Пример #1
0
 public function testSetStartDateAffectsStringOutput()
 {
     $this->rule->loadFromString('FREQ=MONTHLY;COUNT=2');
     $this->assertEquals('FREQ=MONTHLY;COUNT=2', $this->rule->getString());
     $this->rule->setStartDate(new \DateTime('2015-12-10'));
     $this->assertEquals('FREQ=MONTHLY;COUNT=2', $this->rule->getString());
     $this->rule->setStartDate(new \DateTime('2015-12-10'), true);
     $this->assertEquals('FREQ=MONTHLY;COUNT=2;DTSTART=20151210T000000', $this->rule->getString());
     $this->rule->setStartDate(new \DateTime('2015-12-10'), false);
     $this->assertEquals('FREQ=MONTHLY;COUNT=2', $this->rule->getString());
 }
All Usage Examples Of Recurr\Rule::getString