Low Events - PHP error on non-date info in url.
Hi, trying to create an events filter for a given date range using url segments such as
website.com/2014-04-01/2014-05-25
This would display events between April 1 and May 25. This works fine unless someone enters url segments which are not dates for example.
website.com/nothing/nothing
that returns the following error
Message: DateTime::__construct() [datetime.--construct]: Failed to parse time string (nothing) at position 0 (n): The timezone could not be found in the database
Filename: libraries/Low_date.php
Line Number: 448
I have tried using both
{exp:low_events:entries channel="events" date_from="{segment_1}" date_to="{segment_2}" unit="custom" limit="2" show_future_entries="yes" status="open|no_board_display" dynamic_parameters="category" paginate="bottom"}
and
{exp:low_events:entries channel="events" date="{segment_1}; {segment_2}" unit="custom" limit="2" show_future_entries="yes" status="open|no_board_display" dynamic_parameters="category" paginate="bottom"}
Any ideas on how to work around this?
Replies
Low 20 Apr 2014 21:20
Right now, the only fix is editing the core file. Open up libraries/Low_date.php and look up line #448, which reads:
Change that to:
...which should suppress the error and fall back to today as the date.
Phil Brienesse 20 Apr 2014 21:47
That change causes a 500 internal server error. Running php 5.2.17 if that makes a difference.
I was also considering checking the segments with switchee and a regex to make sure they were valid but I am horrible at regex and trying to come up with something that works.
Low 20 Apr 2014 21:56
Hmm, that code does work in php 5.3, so that's looking like some sort of php issue that I cannot work around.
The regex for the date pattern is this:
So you could try that with Switchee.
Low 20 Apr 2014 22:14
Or try and use this code as the replacement instead:
Phil Brienesse 20 Apr 2014 23:03
Yes that works. Returns events from today. That will work. I figured out why regex wasn't working for me too has to do with encoding EE's special characters such as | and }. Did alot of research and came up with this for a date regex. Works well.
{case value="#^((20|21)\d\d)-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$#"}
Thanks for the help didn't expect any resolution on Easter Sunday.