Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule::loadFromString cannot handle DTSTART/DTEND with timezones #137

Open
gregor-tb opened this issue Nov 29, 2017 · 0 comments · May be fixed by #180
Open

Rule::loadFromString cannot handle DTSTART/DTEND with timezones #137

gregor-tb opened this issue Nov 29, 2017 · 0 comments · May be fixed by #180
Labels

Comments

@gregor-tb
Copy link

gregor-tb commented Nov 29, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants