• 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;
    }

  • 相关阅读:
    Command模式应用实践
    .Net中的设计模式——Strategy模式
    PetShop之ASP.NET缓存
    征求书名
    PetShop之业务逻辑层设计
    Buider模式应用实践
    公告:目前博客园书业出版小组的工作进度
    “AS3.0高级动画编程”学习:第二章转向行为(下)
    as3: this,stage,root的测试
    As3.0中的位图(Bitmap/BitmapData)编程
  • 原文地址:https://www.cnblogs.com/bella-life-blog/p/3798919.html
Copyright © 2020-2023  润新知