iCal icon indicating copy to clipboard operation
iCal copied to clipboard

Recurrence rules don't allow multiple values for BYMONTH, BYHOUR, BYMINUTE, BYSECOND

Open lukaswhite opened this issue 5 years ago • 0 comments

Recurrence rules are allowed multiple values for BYMONTH, BYHOUR, BYMINUTE and BYSECOND, for example:

DTSTART;TZID=US-Eastern:19970902T090000
  RRULE:FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40

(source)

However, the corresponding methods (setByMonth(), setByHour(), setByMinute(), setBySecond()) don't allow multiple values; they throw an InvalidArgumentException.

For example:

public function setByMonth($month)
{
    if (!is_integer($month) || $month < 0 || $month > 12) {
        throw new InvalidArgumentException('Invalid value for BYMONTH');
    }

    $this->byMonth = $month;

    return $this;
}

Because it's insisting on a single, integer value, you can't do this:

$rule->setByMonth( '1,3,5' );

By contrast, setByDay() looks like this:

public function setByDay(string $day)
{
    $this->byDay = $day;

    return $this;
}

I'd be happy to submit a PR, it's just a question of whether it's worth validating string values, for example throwing an exception if you did something like this:

$rule->setByMonth( '1,3,13' );

...or...

$rule->setByMonth( 'JAN,MAR,MAY' );

lukaswhite avatar Mar 14 '19 16:03 lukaswhite