Hello,
Please have a look at the following example, it is just a sample code for you to understand.
Code:
static Public long calculation(EventDebut Date, Date eventFin, int plageDebut, int plageFin) {
GregorianCalendar clnd1 = new GregorianCalendar(); / / Novice
GregorianCalendar clnd2 = new GregorianCalendar(); / / End range
long intersection = 0;
/ / It defines the time slot that starts before beginning
clnd1.setTime(eventDebut);
clnd1.set(Calendar.HOUR_OF_DAY, PlageDebut);
clnd1.set(Calendar.MINUTE, 0);
clnd1.set(Calendar.SECOND, 0);
clnd1.set(Calendar.Millisecond, 0);
if (clnd1.getTime().after(eventDebut)) {
clnd1.add(Calendar.DATE, -1);
}
clnd2.setTime(clnd1.getTime());
clnd2.set(Calendar.HOUR_OF_DAY, PlageFin);
if (clnd2.getTime().before(clnd1.getTime())) {
clnd2.add(Calendar.DATE, 1);
}
/ / As long as the slot is not later than end:
while (clnd1.getTime().before(eventFin)) {
+ intersection = Math.max(Math.min(eventFin.getTime(), clnd2.getTimeInMillis()) - Math.max(eventDebut.getTime(), Cal1.getTimeInMillis()), 0);
/ / It shifts the range of 24h
clnd1.add(Calendar.DATE, 1);
clnd2.add(Calendar.DATE, 1);
}
return intersection;
}
Bookmarks