I am trying to write a calendar in PHP. In week view, I want my events to be listed like iCal, where simultaneous events reduces their width to half size.
I have an extremely hard time figuring this one out though, so I hope you can help me. What I want is that if one event is overlapping another, it should set [split] => true on both event arrays – or something in that direction (read: I am unsure whether this is the most efficient solution). Then I can check for split == true in the foreach loop which prints out the events.
Here is an example array containing two simultaneous events:
$events = array(
array(
"id" => 21,
"start" => 1242219600,
"end" => 1242237600,
"title" => "foo",
"split" => false
),
array(
"id" => 22,
"start" => 1242223200,
"end" => 1242234000,
"title" => "foo",
"split" => false
)
);
$events = someFunctionToOffsetEvents($events);
How would you solve this one?
I’ve had to deal with date collision issues alot lately, and the best I’ve been able to come up with is:
date1.start < date2.end and date1.end > date2.start = collision
This simple formula will account for all of the following situations:
Based on your comment this is probably the solution you are looking for:
Note that this solution isn’t very optimized, and should only be used for figuring out a better solution. Never trust code from the web.
*Code has not been tested