0
Given a time frame, I need to know how many hours are longer than 22:00 and shorter than 05:00
LocalDateTime entrada1, saida1, entrada2, saida2, entrada3, saida3;
entrada1 = LocalDateTime.parse(data_rp + " " + rp.getEntrada1(),
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
saida1 = LocalDateTime.parse(data_rp + " " + rp.getSaida1(),
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
entrada2 = LocalDateTime.parse(data_rp + " " + rp.getEntrada2(),
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
if(tem_saida_especial) {
LocalDate hoje = LocalDate.parse(data_rp,
DateTimeFormatter.ofPattern("dd/MM/yyyy"));
LocalDate dia_seguinte = hoje.plusDays(1);
String nova_data = dia_seguinte.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
saida2 = LocalDateTime.parse(nova_data + " " + rp.getSaida2(),
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
}else {
saida2 = LocalDateTime.parse(data_rp + " " + rp.getSaida2(),
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
}
entrada3 = LocalDateTime.parse(data_rp + " " + rp.getEntrada3(),
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
saida3 = LocalDateTime.parse(data_rp + " " + rp.getSaida3(),
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
long periodAsMinutes1 = ChronoUnit.MINUTES.between(entrada1, saida1);
long periodAsMinutes2 = ChronoUnit.MINUTES.between(entrada2, saida2);
long periodAsMinutes3 = ChronoUnit.MINUTES.between(entrada3, saida3);
long duracao_trabalho = periodAsMinutes1 + periodAsMinutes2 + periodAsMinutes3;
total_horas_normais_trabalhadas += duracao_trabalho;
Example of entries: inada1: 23/07/2021 06:58 exit 1: 23/07/2021 11:00 entrada2: 23/07/2021 12:00 out2: 24/07/2021 02:00 duraca_work: 18:10
Basically, in the range of 23/07/2021 06:58 until 24/07/2021 02:00, I need to extract the total of hours between 22:00 and 05:00.
I know it’s 4:00, but how can I program that calculation?
You’re a little confused. If the person worked from 06:58 to 11:00, it is 242 minutes (or 4 hours and 2 minutes), after 12:00 to 02:00 the next day it is 14 hours, totaling 18 hours and 2 minutes. Then you mention the interval between 22:00 and 05:00, which does not appear anywhere (and it is not 4:00 because between 10:00 and 5:00 the next day it is 7:00). Finally, could [Dit] and clarify better what are the dates and times involved and what should be the result?
– hkotsubo