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

Incorrect date generated throws exception #6

Closed
amnuts opened this issue Mar 22, 2011 · 1 comment
Closed

Incorrect date generated throws exception #6

amnuts opened this issue Mar 22, 2011 · 1 comment

Comments

@amnuts
Copy link

amnuts commented Mar 22, 2011

When having the start date and recur rule as below:

$r->recur(new DateTime('2011-03-23 13:00:00'))
  ->rrule('INTERVAL=1;FREQ=WEEKLY;BYDAY=MO,TU,TH,FR;UNTIL=2013-03-25T13:00:00+0000');

it throws the following exception:

Fatal error:  Uncaught exception 'Exception' with message 'DateTime::__construct() [datetime.--construct]: Failed to parse time string (2011-13-1 13:00:00) at position 6 (3): Unexpected character' in /Volumes/cwisnewdev/WWW/tests/wtf/when/When.php:561
Stack trace:
#0 /Volumes/cwisnewdev/WWW/tests/wtf/when/When.php(561): DateTime->__construct('2011-13-1 13:00...')
#1 /Volumes/cwisnewdev/WWW/tests/wtf/when/When.php(719): When->create_suggestions()
#2 /Volumes/cwisnewdev/WWW/tests/wtf/when/When_Iterator.php(97): When->next()
#3 /Volumes/cwisnewdev/WWW/tests/wtf/when/rrule.php(33): When_Iterator->valid()
#4 {main}
  thrown in /Volumes/cwisnewdev/WWW/tests/wtf/when/When.php on line 561

As you can see, it's tried to create a datetime object with the date of '2011-13-1' and an exception is thrown because there aren't 13 months in the year (last time I checked, anyway ;-) ).

The relevant code is:

$tmp_month = $month+1;
$tmp_date = new DateTime($year . '-' . $tmp_month . '-' . $overflow_count . ' ' . $timestamp);
$overflow_count++;

One possible fix would be to make the code:

$tmp_date = new DateTime($year . '-' . $month . '-' . $overflow_count . ' ' . $timestamp);
$tmp_date->modify('+1 month');
$overflow_count++;
@tplaner
Copy link
Owner

tplaner commented Apr 12, 2011

Thanks for the bug report, should be patched now.

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

No branches or pull requests

2 participants