Atitit. Sum up java c ++ c #. net js php,

Source: Internet
Author: User

Atitit. Sum up java c ++ c #. net js php,

Atitit. Summary of methods for judging time overlaps java c ++ c #. net js php

 

1. process logic 1

2. The overlap algorithm is actually the intersection of a date set and a time set (Multiplication Algorithm) 1

3. Code --- 1

4. The final generated SQL 3

5. Refer to 5

 

1. determine the specific process of time overlap

First, determine the date overlap, and then determine the time segment overlap.

Each section contains an inner, exclusive, left inclusive, and right inclusive... therefore, the or expression requires 4*4 = 16 .. each or expression contains four and expressions (two date expressions and two time range expressions)

The final expression requires 16*4 = 64, which is a long one ..

 

Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com

Reprinted please indicate Source: http://blog.csdn.net/attilax

 

2. The overlap algorithm is actually the intersection of a date set and a time set (Multiplication Algorithm)

In programming, there are .....

Answer

It is actually the intersection, union, and difference.
The so-called addition is actually the union of two sets.
Subtraction is the difference set of two sets.
Multiplication is the union of two sets.
They are all from logical operations.

In addition, let's make a correction: Multiplication is the intersection of two sets.

 

 

3. Code ---

Private void ini (){

String db_start_time = "start_time ";

String db_end_time = "end_time ";

String db_include_exp = "db_start_detail> = ui_start and db_end_detail <= ui_end ";

String db_outclude_exp = "db_start_detail <= ui_start and db_end_detail> = ui_end ";

String db_left1_de_exp = "db_end_detail> = ui_start and db_end_detail <= ui_end ";

String db_rit1_de_exp = "db_start_detail> = ui_start and db_end_detail <= ui_end ";

 

 

List <String> dateExpList = new ArrayList <String> (){

{

 

Add (expandFunc (db_include_exp ));

Add (expandFunc (db_outclude_exp ));

Add (expandFunc (db_leftinclude_exp ));

Add (expandFunc (db_ritinclude_exp ));

 

}

 

Private String expandFunc (String db_include_exp ){

String db_start_fld_Datefunc = "CONVERT (varchar (100), db_start_unc, 23 )";

String db_end_fld_Datefunc = "CONVERT (varchar (100), db_end_unc, 23 )";

Return db_include_exp.replaceAll ("db_start_start ",

Db_start_fld_Datefunc). replaceAll ("db_end_unc ",

Db_end_fld_Datefunc );

}

};

 

List <String> timeExpList = new ArrayList <String> (){

{

Add (expandFunc (db_include_exp ));

Add (expandFunc (db_outclude_exp ));

Add (expandFunc (db_leftinclude_exp ));

Add (expandFunc (db_ritinclude_exp ));

 

}

 

Private String expandFunc (String db_include_exp ){

String db_start_fld_Timefunc = "CONVERT (varchar (100), db_start_fld, 8 )";

String db_end_fld_Timefunc = "CONVERT (varchar (100), db_end_fld, 8 )";

Return db_include_exp.replaceAll ("db_start_start ",

Db_start_fld_Timefunc). replaceAll ("db_end_fld ",

Db_end_fld_Timefunc );

}

};

List <String> finalList = new ArrayList <String> (){{

For (String dateExp: dateExpList ){

For (String timeExp: timeExpList ){

This. add (dateExp + "and" + timeExp. replaceAll ("db_start_fld", db_start_fld). replaceAll ("db_end_fld", db_end_fld ));

}

}

}};

String SQL = new ArrayList (){

Private String exec (){

String exp_final = "1 = 1 ";

For (String exp: finalList ){

// If (exp_final.length () = 0)

Exp_final = exp_final + "or (" + exp + ")";

}

Return exp_final;

 

Cmd.exe c ();

System. out. println (SQL );

 

}

 

4. The final generated SQL

 

 

SELECT *

FROM tab

WHERE 1 = 1

OR (CONVERT (varchar (100), db_start_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8) <= ui_start

And convert (varchar (100), end_time, 8)> = ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), end_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23) <= ui_start

And convert (varchar (100), db_end_fld, 23)> = ui_end

And convert (varchar (100), start_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23) <= ui_start

And convert (varchar (100), db_end_fld, 23)> = ui_end

And convert (varchar (100), start_time, 8) <= ui_start

And convert (varchar (100), end_time, 8)> = ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23) <= ui_start

And convert (varchar (100), db_end_fld, 23)> = ui_end

And convert (varchar (100), end_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23) <= ui_start

And convert (varchar (100), db_end_fld, 23)> = ui_end

And convert (varchar (100), start_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_end_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_end_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8) <= ui_start

And convert (varchar (100), end_time, 8)> = ui_end)

OR (CONVERT (varchar (100), db_end_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), end_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_end_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8) <= ui_start

And convert (varchar (100), end_time, 8)> = ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), end_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

OR (CONVERT (varchar (100), db_start_fld, 23)> = ui_start

And convert (varchar (100), db_end_fld, 23) <= ui_end

And convert (varchar (100), start_time, 8)> = ui_start

And convert (varchar (100), end_time, 8) <= ui_end)

 

 

5. Reference

Java time coincidence Time Difference-talented young programmers-Li Rongsheng column-blog channel-CSDN. NET

How to determine whether there is an intersection in two time periods in JAVA-CSDN Forum-CSDN. NET-China's largest IT technology community

Compares the tool classes for collision between two date intervals to determine whether there is an intersection between the two time ranges (unit: Day) Java-and Shen log-Netease blog

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.