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

  • SEARCH
  • Home
  • 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 7503545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:15:40+00:00 2026-05-29T21:15:40+00:00

In a table I have columns with to and from dates, I highlight overlaps

  • 0

In a table I have columns with to and from dates, I highlight overlaps between rows taking into account the periods, this is done exhaustively in nested loops. This is not the issue.
I need the same colour for the rows that overlap.

sub highlight_overlaps {
    my $date_from1;
    my $date_to1;
    my $date_from2;
    my $date_to2;

    my $i = 0;
    my $j = 0;

    for ($i; $i < $#DATE_HOLDER; $i++) {
        $date_from1 = $DATE_HOLDER[$i][0];
        $date_to1   = $DATE_HOLDER[$i][1];

        my $red   = int(rand(65))  + 190;
        my $green = int(rand(290)) - 55;
        my $blue  = int(rand(290)) - 55;

        for ($j=$i+1; $j<=$#DATE_HOLDER; $j++) {
            $date_from2 = $DATE_HOLDER[$j][0];
            $date_to2   = $DATE_HOLDER[$j][1];

            if (($date_from1 le $date_to2   && $date_to1 ge $date_to2) ||
                ($date_from1 le $date_from2 && $date_to1 le $date_to2) ||
                ($date_from1 gt $date_from2 && $date_from1 lt $date_to2)) {

                $tb->setCellStyle($i+2, 6, "background-color:rgb($red,$green,$blue);font-size:9pt");
                $tb->setCellStyle($i+2, 7, "background-color:rgb($red,$green,$blue);font-size:9pt");

                $tb->setCellStyle($j+2, 6, "background-color:rgb($red,$green,$blue);font-size:9pt");
                $tb->setCellStyle($j+2, 7, "background-color:rgb($red,$green,$blue);font-size:9pt");
            }
        }
    }
}

This works fine if it’s just a pair of dates; say:

1) 25-06-2012 27-06-2012

2) 18-06-2012 29-06-2012

Will get the same colour

If though I have

0) 26-06-2012 28-06-2012

1) 25-06-2012 27-06-2012

2) 18-06-2012 29-06-2012

0 will get a different colour while 1 & 2 are paired as intended.

When and how to pick colours so that different colours are only applied to different overlaps?

Following up on the first answer; how may I represent overlaps in order to store them in a data structure, so that I can colour them after their detection?

  • 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-29T21:15:43+00:00Added an answer on May 29, 2026 at 9:15 pm

    You’ll have to compare each interval against each other interval, and put them in ‘buckets’ when they are equal. Now when you compare an interval to a third interval, you put the third in the same bucket as the interval.

    Then you print the buckets.

    Perl’s hash would make for fine buckets.

    About your overlap detection

    There is no overlap if

    • date1_to < date2_from OR
    • date2_to < date1_from

    Or, in Perl:

    if ($date_to1 lt $date_from2 || $date_to2 lt $date_from1) {
    #overlap
    }
    

    Invert that either using Perl’s unless, or using de Morgan:

    if ($date_to1 ge $date_from2 && $date_to2 ge $date_from1) {
    #overlap
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a 300.000 rows table; one of the columns is a varchar() but
I have this simple problem in SQL. I have a table with 4 columns.
I have the following data in a database table, Columns : Date, Hour(from 1
I have table tblEvents with columns dEvent_Date, dEvent_Time, tEvent_Emp_Code_num I must group all dates
I have a large table with input boxes. Three columns of these are dates/times
I have a table of orders with multiple date columns (Department finished dates). I'd
Okay, so, I have a list table with 2 columns: codes and dates. I
I have a dropdown list that holds all the columns name from the table.

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.