Calculation of the end date when skipping holidays + time in Joda

I would like to calculate the end date (and time) of the event. I know the date and duration of the start (in minutes). But:

  • I need to skip the holidays - not a recurring situation
  • I need to skip the weekend - the current situation.
  • I do not need to count working hours (for example: from 8:00 to 17:00) - a repeating situation, but with finer details

Is there an easy way to achieve these cases using the Joda time library?

+6
java jodatime
source share
4 answers

Jodatime will help you - I would say - but you will need to write the logic yourself, the cycle will be missed whole days and several times a day. Not very simple, nor very difficult, it seems to me.

+2
source share

You must define "holidays" first. Not every region has the same ones, so this should be made common and plug-in.

I do not think it is "simple."

+1
source share
+1
source share

Here is the code I'm using. dtDateTimes can contain predefined vacation dates (for example, UK Bank Holidays) and dtConstants can contain duplicate things that you want to match, for example DateTimeConstants.SATURDAY .

 /** * Returns a tick for each of * the dates as represented by the <code>dtConstants</code> or the list of <code>dtDateTimes</code> * occurring in the period as represented by begin -> end. * * @param begin * @param end * @param dtConstants * @param dtDateTimes * @return */ public int numberOfOccurrencesInPeriod(final DateTime begin, final DateTime end, List<Integer> dtConstants, List<DateTime> dtDateTimes) { int counter = 0; for (DateTime current = begin; current.isBefore(end); current = current.plusDays(1)) { for (Integer constant : dtConstants) { if (current.dayOfWeek().get() == constant.intValue()) { counter++; } } for (DateTime dt : dtDateTimes) { if (current.getDayOfWeek() == (dt.getDayOfWeek())) { counter++; } } } return counter; } /** * Returns true if the period as represented by begin -> end contains any one of * the dates as represented by the <code>dtConstants</code> or the list of <code>dtDateTimes</code> * * @param begin * @param end * @param dtConstants * @param dtDateTimes */ public boolean isInPeriod(final DateTime begin, final DateTime end, List<Integer> dtConstants, List<DateTime> dtDateTimes) { return numberOfOccurrencesInPeriod(begin, end, dtConstants, dtDateTimes) > 0; } 
0
source share

All Articles