Skip to content
New issue

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

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

Already on GitHub? # to your account

An RRule created with a timestamp start date generates an invalid RFC string #15

Closed
abrahamguo opened this issue Aug 4, 2016 · 5 comments
Labels

Comments

@abrahamguo
Copy link

abrahamguo commented Aug 4, 2016

<?php
    date_default_timezone_set("America/Chicago");
    require "inc/php-rrule/RRuleInterface.php";
    require "inc/php-rrule/RRule.php";
    require "inc/php-rrule/RSet.php";
    use RRule\RRule;

    $rrule = new RRule(array(
        "freq" => "WEEKLY",
        "dtstart" => 1470323171,
        "interval" => 1
    ));

    $rfcString = $rrule->rfcString();
    echo "<b>The RFC string is:</b> " . $rfcString . "<br><br>";
    echo "<b>Parsing RFC string:</b> ";
    $new_rrule = new RRule($rfcString);

generates the following output:

The RFC string is: DTSTART;TZID=+00:00:20160804T150611 RRULE:FREQ=WEEKLY

Parsing RFC string: Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Invalid DTSTART property: date or date time format incorrect' in /path/to/php-rrule/RRule.php:649

This is because the RFC string generated has the timezone set as "+00:00" rather than "UTC".

@rlanvin
Copy link
Owner

rlanvin commented Aug 4, 2016

Yep that's a bug alright, thanks for the report.

On a related note: when you create the rule with a timestamp, do you expect the results (and the RFC string generated) to be in your timezone (America/Chicago in your example)? At the moment they are in UTC since a timestamp is UTC (by definition) but I'm curious to know what you think.

@abrahamguo
Copy link
Author

Yeah, I think that keeping the results in UTC is probably the correct way to do it. Otherwise, users might get unexpected results (because of a default timezone setting somewhere) that will be hard to track down where they are coming from.

rlanvin added a commit that referenced this issue Aug 7, 2016
PHP's default is to put them in "+00:00" timezone, which
generates invalid RFC string.
The method rfcString() will convert all invalid timezones to
UTC to generate a valid RFC string.
@rlanvin
Copy link
Owner

rlanvin commented Aug 7, 2016

Thanks. I pushed a fix on dev-master, could you try and let me know if it solves your problem?

@abrahamguo
Copy link
Author

Yep, seems to be working now!

@rlanvin
Copy link
Owner

rlanvin commented Aug 9, 2016

Thanks!

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

No branches or pull requests

2 participants