Date segment intersection judgment method, date intersection judgment

Source: Internet
Author: User

Date segment intersection judgment method, date intersection judgment

Two days ago, I encountered an intersection problem. An activity can be held only once in a period of time. You need to determine whether the activity time range already exists. Then, I listed the following expression:

------------------------ Original activity time ------------------------------
Time period
Start a1
End a1

Time period B
Start b1
End b2

Time period c
Start c1
End c2

------------------------------------------------------

List <date> activityList = new List <date> {a, B, c}

New activity release time

Time period n
Start n1
End n2

Foreach (var item in activityList)
{
// The intersection of time period n and time period item appears when n2> = item1 & n1 <= item2

If (n2> = item1 & n1 <= item2)

{

// Intersection time. the start time is set to begin and the end time is set to a small value.

 

}

}

It's quite easy to sort it out.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.