我目前正在致力於HR system
,並且它在休假管理模塊中有一個選項,用於請假get 10 consecutive days (working days except weekends)
。它是一個J2EE應用程序。從給定日期起連續獲得'N'個連續工作日
所有我想要的是get 'N' number of consecutive weekdays from the given date
有誰知道如何實現這個問題?
P.S:我不使用任何第三方庫像JodaTime ..
這裏是我的控制器的單天的假期的應用程序代碼。它與連續的日子無關。但是這張貼在這裏,以證明我在做正經事..
if (action.equals("applyLeave")) {
Leave l = new Leave();
int userid = Integer.parseInt(request.getParameter("userid"));
int leavetype = Integer.parseInt(request.getParameter("leavetype"));
String from = request.getParameter("from"); // from time
String to = request.getParameter("to"); // to time
double total = Double.parseDouble(request.getParameter("total")); // total hours
String r1 = request.getParameter("rep1");
String r2 = request.getParameter("rep2");
if (r1 == null || r1.isEmpty()) {
r1 = "0";
}
if (r2 == null || r2.isEmpty()) {
r2 = "0";
}
int rep1 = Integer.parseInt(r1);
int rep2 = Integer.parseInt(r2);
String reason = request.getParameter("reason");
String date = request.getParameter("date");
l.setUser(userid);
l.setLeavetype(leavetype);
l.setDate(date);
l.setFrom(from);
l.setReason(reason);
l.setRep1(rep1);
l.setRep2(rep2);
l.setTo(to);
l.setTotal(total);
dao.saveLeave(l);
// get manager of the department
UserDao udao = (UserDao) ctx.getBean("udao");
DepartmentDao ddao = (DepartmentDao) ctx.getBean("depdao");
NotificationDao notificationDao = (NotificationDao) ctx.getBean("notificationDao");
User u = udao.getUserByUserID(userid).get(0);
int department = u.getDepartment();
Department d = ddao.getDepartmentByID(department).get(0);
int manager = d.getManager();
// save a notification for the respective manager
// insert notification
String text = u.getFirstname() + " " + u.getLastname() + " has applied for a leave";
Notification n = new Notification();
n.setUserid(manager);
n.setFk(dao.getLeaveID());
n.setType(3);
n.setText(text);
notificationDao.saveNotification(n);
PrintWriter out = res.getWriter();
res.setContentType("text/html");
Gson gson = new Gson();
JsonObject myObj = new JsonObject();
myObj.add("message", gson.toJsonTree("Successfully Inserted"));
out.println(myObj.toString());
out.close();
}
@Psioniax,我已經完成了大部分的應用程序中的事情,但我竭力讓這個連續數天。我已經搜索谷歌的解決方案,但我找不到任何.. –
編輯您的問題,包括一些代碼 –
@Psioniax,編碼 –