recurr icon indicating copy to clipboard operation
recurr copied to clipboard

Rule::loadFromString cannot handle DTSTART/DTEND with timezones

Open gregor-tb opened this issue 7 years ago • 0 comments

Hi,

because loadFromString actually makes a explode(';') to create an array for loadFromArray, timezones are broken here, e.g.:

DTSTART;TZID=UTC:20150209T153000

This is not covered by the unittest :(

I suggest to extend each test to be sure that results from getString() can always be used to recreate the object and both are equal:

        $begin = new DateTimeImmutable('2012-08-01');
        $end = new DateTimeImmutable('2012-08-31');

        $rule = new Rule('FREQ=WEEKLY;COUNT=5');
        $rule->setStartDate($begin, true);
        $rule->setEndDate($end);

        $string = $rule->getString();
        $ruleRestored = Rule::createFromString($string);

        $this->assertEquals($rule, $ruleRestored); // Fails

Similar problem is, that you can control, to add/remove DTSTART for the rules, but not DTEND, so this also is not predictable, this test fails also:

        $begin = new DateTime('2012-08-01');
        $end = new DateTime('2012-08-31');
        $xmas = new DateTime('2012-12-25');

        $rule = new Rule('FREQ=WEEKLY;COUNT=5', $begin, $end);
        $string = $rule->getString();

        $this->assertEquals('FREQ=WEEKLY;COUNT=5;DTEND=20120831T000000', $string); // passes

        $ruleRestored = new Rule($rule->getString(), $begin, $xmas);

        $this->assertNotEquals($rule, $ruleRestored); // fails

But this has a total different behaviour:

        $begin = new DateTimeImmutable('2012-08-01');
        $end = new DateTimeImmutable('2012-08-31');
        $xmas = new DateTimeImmutable('2012-12-25');

        $rule = new Rule('FREQ=WEEKLY;COUNT=5', $begin, $end);
        $string = $rule->getString();

        $this->assertEquals('FREQ=WEEKLY;COUNT=5;DTEND=20120831T000000', $string); // fails

        $ruleRestored = new Rule($rule->getString(), $begin, $xmas);

        $this->assertNotEquals($rule, $ruleRestored); // unknown

Here we don't get any DTEND, because of

        // DTEND
        if ($this->endDate instanceof \DateTime) {

This should check for DateTimeInterface I guess.

Thanks for your work, best regards Gregor

gregor-tb avatar Nov 29 '17 18:11 gregor-tb