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

Exception causing trouble in PHP 5.2.13 #5

Closed
barlow opened this issue Jan 30, 2011 · 5 comments
Closed

Exception causing trouble in PHP 5.2.13 #5

barlow opened this issue Jan 30, 2011 · 5 comments

Comments

@barlow
Copy link

barlow commented Jan 30, 2011

With an RRULE such as:

FREQ=MONTHLY;

my production version of PHP (5.2.13) was throwing an exception because of code at around line 630. The message was:
Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (last day of 1 month) at position 9 (o):

The offending line of code was:
$this->try_date->modify('last day of ' . $this->interval . ' ' . $interval);

I believe this version of PHP could not understand 'last day of'.

Now, I'm not sure what the intent of the code was here, but I'm assuming you are wanting to move the date ahead a certain (interval) number of months, landing on the last day of the month. My solution was:

for ($i=0; $i< $this->interval; $i++)
{
$this->try_date->modify('+ 28 days');
$this->try_date->setDate($this->try_date->format('Y'), $this->try_date->format('m'), $this->try_date->format('t'));
}

The +28 days ensure we dont skip a smaller month, and the format('t') gives us the last date of the month in question.

@tplaner
Copy link
Owner

tplaner commented Feb 3, 2011

You are correct, last day of wasn't added until 5.3 according to the comments on http://us.php.net/manual/en/datetime.formats.relative.php

If you would like, feel free to fork the project, and submit a pull request with your modifications. If not I should have some time to look into/fix this issue over the weekend.

Thank you for pointing this out.

@freshface
Copy link

Is this fixed?
I have this error:

Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (last day of 1 month) at position 9 (o): The timezone could not be found in the database in /home/figure8/domains/billing.figure8.be/external/When.php on line 624

@barlow
Copy link
Author

barlow commented Nov 10, 2011

Hi Frederik,

No, not fixed.

I use the modification mentioned in the post, this works with the
earlier PHP version.

So clause around line 624 in my version of When.php is this:

if($interval == "month")
{
//cjb 'last day of 1 month' does not work
//$this->try_date->modify('last day of ' . $this->interval . ' ' .
$interval);
//$this->try_date->modify('+ ' . $this->interval . ' ' . $interval);

  for ($i=0; $i< $this->interval; $i++)
  {
     $this->try_date->modify('+ 28 days');
     $this->try_date->setDate($this->try_date->format('Y'), 

$this->try_date->format('m'), $this->try_date->format('t'));
}
}

Does that help?
Chris

On 11/10/2011 1:41 AM, Frederik Heyninck wrote:

Is this fixed?
I have this error:

Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (last day of 1 month) at position 9 (o): The timezone could not be found in the database in /home/figure8/domains/billing.figure8.be/external/When.php on line 624


Reply to this email directly or view it on GitHub:
#5 (comment)

@freshface
Copy link

It fixes it, thx.

@outrunthewolf
Copy link

This works, but it doesn't give accurate dates. Which is whay I turned to "last day of" in the first place Perhaps i'm doing something wrong?

tplaner added a commit that referenced this issue Aug 9, 2013
Pull request for Issue #5 - Exception causing trouble in PHP 5.2.13
@tplaner tplaner closed this as completed Mar 12, 2015
mhnrm pushed a commit to itagenten/When that referenced this issue Mar 16, 2016
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

4 participants