Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 218811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:47:10+00:00 2026-05-11T18:47:10+00:00

I am trying to write a calendar in PHP. In week view, I want

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:47:11+00:00Added an answer on May 11, 2026 at 6:47 pm

    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:

    --same for all situations:
    date1.start = 1/1/2009
    date1.end = 1/10/2009
    
    --Start date is in first dates range:
    date2.start = 1/9/2009
    date2.end = 2/10/2009
    
    --End date is in first dates range:
    date2.start = 12/10/2008
    date2.end = 1/3/2009
    
    --Start & End date is inside first dates range:
    date2.start = 1/2/2009
    date2.end = 1/3/2009
    
    --First date is inside of second dates range:
    date2.start = 12/1/2008
    date2.end = 2/1/2009
    
    $date1 = array('start' => '2009-01-05', 'end' => '2009-01-10');
    $date2 = array('start' => '2009-01-01', 'end' => '2009-01-04'); // end inside one
    $date3 = array('start' => '2009-01-04', 'end' => '2009-01-15'); // start inside one
    $date4 = array('start' => '2009-01-01', 'end' => '2009-01-15'); // one inside me
    $date5 = array('start' => '2009-01-04', 'end' => '2009-01-05'); // inside one
    
    function datesCollide($date1, $date2)
    {
        $start1TS = strtotime($date1['start']);
        $end1TS = strtotime($date1['end']);
        $start2TS = strtotime($date2['start']);
        $end2TS = strtotime($date2['end']);
    
        if ($start1TS <= $end2TS && $end1TS >= $start2)
        {
            return true;
        }
    
        return false;
    }
    

    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.

    $events = array(
      array(
            "id" => 21,
            "start" => 1242219600,
            "end" => 1242237600,
            "title" => "foo",
            "split" => false
      ),
      array(
            "id" => 22,
            "start" => 1242223200,
            "end" => 1242234000,
            "title" => "foo",
            "split" => false
      )
    );
    
    foreach ($events as $key => $event)
    {
        $events[$key]->split = dateCollisionCheck($event, $events);
    }
    
    function dateCollisionCheck(&$event, &$eventList)
    {
        foreach ($eventList as $checkEvent)
        {
            if ($event->id != $checkEvent->id)
            {
                if ($event->start <= $checkEvent->end && $event->end >= $checkEvent->start)
                {
                    return true; // return as soon as we know there is a collision
                }
            }
        }
    
        return false;
    }
    

    *Code has not been tested

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 248k
  • Answers 248k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer That will be awesome duel to watch. Just like the… May 13, 2026 at 8:49 am
  • Editorial Team
    Editorial Team added an answer If you're dealing with a large data set, I would… May 13, 2026 at 8:49 am
  • Editorial Team
    Editorial Team added an answer I'd probably create a DialogBox with the TOS text in… May 13, 2026 at 8:49 am

Related Questions

I'm making a custom event calendar with PHP. I am trying to get the
I have a django model for an appointment in a calendar that I am
I am trying to extract data out an Oracle table. The column is defined
I am having a peculiar problem with the order in which FlowLayoutPanels are added

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.