The return value: end date
Stored in the database the holiday information
The CREATE TABLE ` tpm_holiday ` (
` id ` varchar (36), NOT NULL COMMENT 'primary key',
` time ` datetime DEFAULT NULL COMMENT 'date',
DEFAULT NULL ` type ` varchar (1) the COMMENT 'type'
The PRIMARY KEY (` id `)
)
Is represented types are divided into two (1 holidays/paid leave; Is 2 working days)
Saturday and Sunday the default for day off,
The week on Friday will have holidays or paid leave date into database; When Saturday or Sunday is adjusted for weekday will date into database
Where bosses can be solved, such as Java or js can, thank you very much!
CodePudding user response:
Import the Java. Text. The DateFormat;
Import the Java. Text. A ParseException;
import java.text.SimpleDateFormat;
Import the Java. Util. Calendar;
import java.util.Date;
Import the Java. Util. HashMap;
Import the Java. Util. The Map;
Public class TestGzr {
The static DateFormat df=new SimpleDateFormat (" yyyy - MM - dd ");
Public static String JSRQ (String startDate, int days, MapMap) {
The Date the Date=null;
Try {
The date=df. Parse (startDate);
} the catch (ParseException e) {
}
int i=0;
While (I & lt; Days) {
//get date is working day or holiday
The int type=getDayType (date, map);
If (type==2) {
//if it is working day
i++;
}
If (I==days) {
break;
}
//date will be delayed 1 day
Calendar c=Calendar.getInstance();
C.s. etTime (date);
C.a. dd (Calendar DATE, 1);
Be sad etTime chtistina georgina rossetti.british poetess date=();
}
Return df. The format (date);
}
/* *
* determine a given date is working day or holiday
*
* @ param date
* @ param map
* @ the return holiday return 1, 2 working days return
*/
Public static int getDayType (Date Date, MapMap) {
//if there is a map, the direct return to map the number in the
If (map. Either containsKey (df) format (date))) {
Return to the map. The get (df) format (date));
}
//it is several weeks
Calendar c=Calendar.getInstance();
C.s. etTime (date);
Be sad et chtistina georgina rossetti.british poetess int day=(Calendar. DAY_OF_WEEK);
If (1 day==| | day==7) {
return 1;
} else {
Return 2;
}
}
Public static void main (String [] args) {
Mapmap=new HashMap (a);
//remove data in the database in the map, the key to date, int for type
//if the amount of data in the database is very much, can according to the start date and treads working days according to the rules to take partial data
The map. The put (" 2021-02-07 ", 2);
The map. The put (" 2021-02-11 ", 1);
The map. The put (" 2021-02-12 ", 1);
The map. The put (" 2021-02-15 ", 1);
The map. The put (" 2021-02-16 ", 1);
The map. The put (" 2021-02-17 ", 1);
The map. The put (" 2021-02-20 ", 2);
System. The out. Println (JSRQ (" 2021-02-01 ", 3, map));
System. The out. Println (JSRQ (" 2021-02-01 ", 6, map));
System. The out. Println (JSRQ (" 2021-02-01 ", 7, map));
System. The out. Println (JSRQ (" 2021-02-01 ", 10, map));
System. The out. Println (JSRQ (" 2021-02-01 ", 15, map));
}
}
Results:
The 2021-02-03
The 2021-02-07
The 2021-02-08
The 2021-02-18
2021-02-24