1

I need to get the MinutesRendered on a specific job on my program. I have the startdate and enddate of that particular job. I need to count the difference between these 2 dates while skipping the holidays, weekends and only counting 8am-5pm per working days (Mon-Fri).

I find it hard to come-up with a logic that will do this. Is there any existing logic or snippet (not really have to be JAVA) that will show me how can this be possible?

Audrick
  • 23
  • 3

1 Answers1

1

A sample program could be for the logic you are asking for is

public static void main(String[] args){

       LocalDateTime startDate = LocalDateTime.now(), endDate = LocalDateTime.now().plusDays(15);

       //List<String> holidays = Arrays.asList([HOLIDAY_LIST]);
       long days = ChronoUnit.DAYS.between(startDate, endDate);
       int daysCount = 0;
       for(int i=0;i<days;i++) {
           if(!("SATURDAY".equals(startDate.plusDays(i).getDayOfWeek().toString()) || "SUNDAY".equals(startDate.plusDays(i).getDayOfWeek().toString()))) {
               daysCount++;
           }
       }

       long minusMinutes = daysCount * 900;
       System.out.println(ChronoUnit.MINUTES.between(startDate, endDate) - minusMinutes);      

    }

In the above code, [HOLIDAY_LIST] depends on you as you have to mention in List as I specified in the commented code.

Harshit
  • 5,147
  • 9
  • 46
  • 93