i have a db table:
events
id
title
start_stamp (unix timestamp)
end_stamp (unit timestamp)
start_date (mm/dd/yyyy)
start_m (mm)
start_d (dd)
start_y (yyyy)
end_date (mm/dd/yyyy)
recurring (0 or 1)
recur_freq (weekly, biweekly, or monthly)
recur_times (int between 1 and 12)
Given a search window, i want to detect any events that occur within my search window.
So far, I have something like this:
define('EVENT_DURATION_THRESHOLD', 60*60*2); // two hours
$search_start = mktime(0,0,0,2,1,2006);
$search_end = mktime(0,0,0,2,5,2006);
$sql = "SELECT * FROM events WHERE
(start_stamp >= " . $search_start . " AND start_stamp <= " . $search_end . ") OR ((e.start_stamp < " . $search_start . ") AND (e.end_stamp IS NOT NULL) AND (e.end_stamp > " . ($search_start + EVENT_DURATION_THRESHOLD) . " ))";
But what is KILLING ME is the recurring events. some events which have recurring = 1 and recur_freq specified as weekly/biweekly/monthly. how can i determine if a recurrence of one of these events will over lap with my search window?
Complicating matters is DAYLIGHT SAVINGS TIME. Whose idea was that anyway? Ben Franklin? Asshole. Anyways, check this out:
<?
$event_start = mktime(8,0,0,2,15,2006);
$recur_period = 60*60*24*7; // 7 days
for($i=0; $i<10; $i++) {
$tmp_time = $event_start + ($i*$recur_period);
$tmp_end = $tmp_time + $d;
echo ' ' . ($i+1) . ' - ' . date('M d, Y \a\t G:i:s', $tmp_time) . '<br>';
}
?>
Here is what comes out...time shifts from 8pm to 10 pm when DST kicks in:
1 - Feb 15, 2006 at 8:00:00 to 8:00:00
2 - Feb 22, 2006 at 8:00:00 to 8:00:00
3 - Mar 01, 2006 at 8:00:00 to 8:00:00
4 - Mar 08, 2006 at 8:00:00 to 8:00:00
5 - Mar 15, 2006 at 8:00:00 to 8:00:00
6 - Mar 22, 2006 at 8:00:00 to 8:00:00
7 - Mar 29, 2006 at 8:00:00 to 8:00:00
8 - Apr 05, 2006 at 9:00:00 to 9:00:00
9 - Apr 12, 2006 at 9:00:00 to 9:00:00
10 - Apr 19, 2006 at 9:00:00 to 9:00:00
make this change to straighten out the times.
// $tmp_time = $event_start + ($i*$recur_period);
$tmp_time = strtotime('+' . ($i*$recur_period_days) . ' days', $event_start);
I am so confused about this. As far as i know the website will never need to display those dates...i just noticed it while working on this. On the OTHER hand, if i come up with some kind of query i'm wondering if it could possibly work accurately.