package com.hzf.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.lang.*;
public class HolidayUtil {
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/**
* 判断sNum个日后的工作日
* @param list 工作日以及节假日
* @param sNum 几日之后的工作人
* @return
* @throws ParseException
*/
public static Date getScheduleActiveDate(List<String> list,int sNum) throws ParseException{
Date today = new Date();
Date tomorrow = null;
int delay =1;
int num = sNum;
while(delay <= num){
tomorrow = getTomorrow(today);
if(!isWeekend(sdf.format(tomorrow)) && !isHoliday(sdf.format(tomorrow),list)){
delay++;
today = tomorrow;
}else if(isWeekend(sdf.format(tomorrow))){
today = tomorrow;
System.out.println(sdf.format(tomorrow) + "::是周末!");
}else if(isHoliday(sdf.format(tomorrow),list)){
today = tomorrow;
System.out.println(sdf.format(tomorrow) + "::是节假日!");
}
}
System.out.println("10个工作日后,即计划激活日期为::" + sdf.format(today));
return today;
}
/**
* 获取明天的日期
* @param date
* @return
*/
public static Date getTomorrow(Date date){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(calendar.DAY_OF_MONTH,+1);
date = calendar.getTime();
return date;
}
/**
* 判断是否是weekend
* @param sdate
* @return
* @throws ParseException
*/
public static boolean isWeekend(String sdate) throws ParseException{
Date date = sdf.parse(sdate);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if(cal.get(Calendar.DAY_OF_WEEK)== Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK)== Calendar.SUNDAY){
return true;
}else{
return false;
}
}
/**
* 判断是否是holiday
* @param sdate
* @param list
* @return
*/
public static boolean isHoliday(String sdate, List<String> list){
if(list.size() > 0){
for(int i = 0; i < list.size(); i++){
if(sdate.equals(list.get(i))){
return true;
}
}
}
return false;
}
}