calculate Leave Days

//根据传入的日期得到周末.
public static int getDayOfWeek(Date date){
Calendar cal=Calendar.getInstance();
cal.setTime(date);
int dayNum=0;
if(cal.get(Calendar.DAY_OF_WEEK)==1){
dayNum = 7;
}else{
dayNum=cal.get(Calendar.DAY_OF_WEEK)-1;
}
return dayNum;
}

//get holidays except weekends //得到除周末以外的节假日.
public int getHolidayDays(Date startDate, Date endDate, String employeeId) {
int weekends = 0;
List<Holiday> l = holidayService.getHolidayList(startDate, endDate,
employeeId);
if (l == null) {
return 0;
} else {
for (Holiday h : l) {
int dayNum = DateTimeUtil.getDayOfWeek(h.getHolidayDate());
if (dayNum == 6 || dayNum == 7) {
weekends = weekends + 1;
}
}
}
return l.size() - weekends;
}

//得到两个日期除周末外之间的天数
public static int getWorkDays(Date startDate,Date endDate) throws ParseException {
int workdays = 0;
while (startDate.compareTo(endDate) <= 0) {
if (getDayOfWeek(startDate) != 6 && getDayOfWeek(startDate) != 7){
workdays++;
}
startDate=getNextDate(startDate);
}
return workdays;
}
//得到下一个日期
public static Date getNextDate(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, 1);
return cal.getTime();
}

public static Boolean isWeekendsDays(Date date) {
int dayNum = getDayOfWeek(date);
return dayNum == 6 || dayNum == 7;
}

calculate Leave Days

时间: 2024-08-27 20:54:09

calculate Leave Days的相关文章

HDU 2114 Calculate S(n)(公式)

Calculate S(n) Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9640    Accepted Submission(s): 3492 Problem Description Calculate S(n). S(n)=13+23 +33 +......+n3 . Input Each line will contain

HDU 1012 u Calculate e【暴力打表,水】

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46844    Accepted Submission(s): 21489 Problem Description A simple mathematical formula for e is where n is allowed to go to infini

线段树 + 矩阵 --- ZOJ 3772 Calculate the Function

Calculate the Function Problem's Link:   http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3772 Mean: 略 analyse: 简单的线段树维护矩阵. 矩阵乘法的结合律(a * b * c == a * (b * c)),注意矩阵乘法不满足分配率(a *b != b * a). 令 M[x] = [1 A[x]]              [1     0 ] ,那么有 [ F

Exercise 3.3 Calculate a discounted price

Exercise 3-3. Write a program that will calculate the price for a quantity entered from the keyboard, given that the unit price is $5 and there is a discount of 10 percent for quantities over 30 and a 15 percent discount for quantities over 50. 1 //

Calculate the formula

Problem Description You just need to calculate the sum of the formula: 1^2+3^2+5^2+……+ n ^2. Input In each case, there is an odd positive integer n. Output Print the sum. Make sure the sum will not exceed 2^31-1 Sample Input 3 Sample Output 10 用普通的做法

hdu 1012:u Calculate e(数学题,水题)

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28686    Accepted Submission(s): 12762 Problem Description A simple mathematical formula for e iswhere n is allowed to go to infinit

Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5

Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved 此问题的解决: 1.要确认spring sts已经设置代理 2.要确认windows -> Preferences -> maven 的settings.xml文件中,设置代理. 3.C:\Users\ttt\.m2\

HDU2139 Calculate the formula【水题】

Calculate the formula Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7441    Accepted Submission(s): 2284 Problem Description You just need to calculate the sum of the formula: 1^2+3^2+5^2+--+

HDU2114 Calculate S(n)【数学】

Calculate S(n) Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8423    Accepted Submission(s): 3060 Problem Description Calculate S(n). S(n)=13+23 +33 +......+n3 . Input Each line will contain

ZOJ 3772 Calculate the Function 线段树+矩阵

Calculate the FunctionTime Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Appoint description:  System Crawler  (2014-04-09) Description You are given a list of numbers A1A2 .. AN and M queries. For the i-th query